network.go 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. package service
  2. import (
  3. "context"
  4. "database/sql"
  5. "fmt"
  6. "log"
  7. "math"
  8. "sort"
  9. "strings"
  10. "time"
  11. . "app.yhyue.com/moapp/jybase/common"
  12. . "app.yhyue.com/moapp/jybase/date"
  13. "app.yhyue.com/moapp/jybase/encrypt"
  14. . "app.yhyue.com/moapp/jybase/es"
  15. . "app.yhyue.com/moapp/jybase/sort"
  16. . "bp.jydev.jianyu360.cn/CRM/application/api/common"
  17. "bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
  18. "github.com/shopspring/decimal"
  19. "github.com/zeromicro/go-zero/core/logx"
  20. )
  21. var Network = &network{}
  22. type network struct {
  23. }
  24. type networkTree struct {
  25. Count int64 `json:"count"`
  26. Name string `json:"name"`
  27. Children []*networkTreeChild `json:"children"`
  28. }
  29. type networkTreeChild struct {
  30. Count int64 `json:"count"`
  31. Id int64 `json:"id"`
  32. CompanyId string `json:"companyId"`
  33. CompanyName string `json:"companyName"`
  34. Type string `json:"type"`
  35. CreateTime string `json:"createTime"`
  36. }
  37. func (s *networkTree) Len() int {
  38. return len(s.Children)
  39. }
  40. func (s *networkTree) Less(i, j int) bool {
  41. if s.Name == "甲方" {
  42. return s.Children[i].CompanyName < s.Children[j].CompanyName
  43. }
  44. it, err1 := time.ParseInLocation(Date_Full_Layout, s.Children[i].CreateTime, time.Local)
  45. if err1 != nil {
  46. return true
  47. }
  48. jt, err2 := time.ParseInLocation(Date_Full_Layout, s.Children[j].CreateTime, time.Local)
  49. if err2 != nil {
  50. return true
  51. }
  52. return it.Unix() < jt.Unix()
  53. }
  54. func (s *networkTree) Swap(i, j int) {
  55. s.Children[i], s.Children[j] = s.Children[j], s.Children[i]
  56. }
  57. type projectInfo struct {
  58. BuyerCount int64
  59. ProjectCount int64
  60. ProjectAmount float64
  61. MonitorCount int64
  62. ExportId []string
  63. }
  64. type firstpartyNetwork struct {
  65. CompanyId string
  66. CompanyName string
  67. Name string
  68. }
  69. type idName struct {
  70. Id string
  71. Name string
  72. }
  73. type introduceOwnerProject struct {
  74. Networks []*myNetwork
  75. FirstpartyNetwork map[string][]*firstpartyNetwork
  76. Firstparty map[string]*projectInfo
  77. Supplier map[string]*projectInfo
  78. Adiffb map[string]*projectInfo
  79. Agency map[string]*projectInfo
  80. Middleman map[string]*projectInfo
  81. }
  82. type myNetwork struct {
  83. Id int64
  84. Company_id string
  85. Company_name string
  86. Qyxy_id string
  87. Itype int64
  88. Person string
  89. Phone string
  90. Buyer_count int64
  91. Project_count int64
  92. Relate_buyer_id string
  93. Relate_project_id string
  94. Create_time string
  95. }
  96. //人脉库-添加/修改人脉
  97. func (n *network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
  98. reply := &types.Reply{Data: map[string]interface{}{
  99. "status": 0,
  100. }}
  101. if in.Type != "middleman" && in.Company_id == "" {
  102. return reply
  103. }
  104. if in.Company_name == "" {
  105. in.Company_name = "未填写"
  106. }
  107. nowFormat := NowFormat(Date_Full_Layout)
  108. var saveIntroduce = func(tx *sql.Tx, cid int64, isUpdate bool) bool {
  109. if in.Type != "middleman" {
  110. return true
  111. } else if in.Introduce_owner_id == "" || in.Introduce_project_id == "" {
  112. return false
  113. }
  114. values := []interface{}{}
  115. ioi := strings.Split(in.Introduce_owner_id, ",")
  116. ioqi := strings.Split(in.Introduce_owner_qyxy_id, ",")
  117. ion := strings.Split(in.Introduce_owner_name, ",")
  118. if len(ioi) != len(ion) || len(ioi) != len(ioqi) {
  119. return false
  120. }
  121. for k, v := range ioi {
  122. values = append(values, in.PositionId, in.EntId, in.EntDeptId, in.EntUserId, cid, ioqi[k], v, ion[k], 1, nowFormat)
  123. }
  124. ipi := strings.Split(in.Introduce_project_id, ",")
  125. ipn := strings.Split(in.Introduce_project_name, ",")
  126. if len(ipi) != len(ipn) {
  127. return false
  128. }
  129. for k, v := range ipi {
  130. values = append(values, in.PositionId, in.EntId, in.EntDeptId, in.EntUserId, cid, nil, v, ipn[k], 2, nowFormat)
  131. }
  132. var r2 int64
  133. if isUpdate {
  134. r2 = CrmMysql.UpdateOrDeleteBySqlByTx(tx, `delete from crm.connection_introduce where connection_id=? and position_id=?`, in.Id, in.PositionId)
  135. }
  136. r3, _ := CrmMysql.InsertBatchByTx(tx, "crm.connection_introduce", []string{"position_id", "ent_id", "ent_dept_id", "ent_user_id", "connection_id", "qyxy_id", "relate_id", "relate_name", "itype", "create_time"}, values)
  137. return r2 >= 0 && r3 > 0
  138. }
  139. itype := n.TypeStrConvert(in.Type)
  140. if in.Id > 0 {
  141. if CrmMysql.ExecTx("更新人脉", func(tx *sql.Tx) bool {
  142. if in.Company_id != "" {
  143. count := CrmMysql.CountBySql(`select count(1) as count from crm.connection where position_id=? and company_id=? and itype=? and id<>? and status=1`, in.PositionId, in.Company_id, itype, in.Id)
  144. if count == -1 {
  145. return false
  146. } else if count > 0 {
  147. reply.Data = map[string]interface{}{
  148. "status": -1,
  149. }
  150. return false
  151. }
  152. }
  153. r1 := CrmMysql.UpdateOrDeleteBySqlByTx(tx, `update crm.connection set company_name=?,company_id=?,contact_person=?,contact_phone=?,update_time=? where id=? and position_id=?`, in.Company_name, in.Company_id, in.Contact_person, in.Contact_phone, nowFormat, in.Id, in.PositionId)
  154. return r1 >= 0 && saveIntroduce(tx, in.Id, true)
  155. }) {
  156. reply.Data = map[string]interface{}{
  157. "status": 1,
  158. }
  159. }
  160. } else {
  161. if in.Company_id != "" {
  162. count := CrmMysql.CountBySql(`select count(1) as count from crm.connection where position_id=? and company_id=? and itype=? and status=1`, in.PositionId, in.Company_id, itype)
  163. if count == -1 {
  164. return reply
  165. } else if count > 0 {
  166. reply.Data = map[string]interface{}{
  167. "status": -1,
  168. }
  169. return reply
  170. }
  171. }
  172. var r1 int64
  173. if CrmMysql.ExecTx("新增人脉", func(tx *sql.Tx) bool {
  174. _, r1 = CrmMysql.InsertBatchByTx(tx, "crm.connection", []string{"position_id", "ent_id", "ent_dept_id", "ent_user_id", "itype", "company_name", "company_id", "qyxy_id", "contact_person", "contact_phone", "status", "create_time", "update_time"}, []interface{}{in.PositionId, in.EntId, in.EntDeptId, in.EntUserId, itype, in.Company_name, in.Company_id, in.Qyxy_id, in.Contact_person, in.Contact_phone, 1, nowFormat, nowFormat})
  175. return r1 > 0 && saveIntroduce(tx, r1, false)
  176. }) {
  177. reply.Data = map[string]interface{}{
  178. "status": 1,
  179. "id": r1,
  180. }
  181. }
  182. }
  183. return reply
  184. }
  185. //人脉库-业主名称联想
  186. func (n *network) Associate(in *types.AssociateReq) (reply *types.Reply) {
  187. //类型;firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 middleman_owner:中间人-业主 middleman_project:中间人-项目 agency:招标代理机构
  188. res := []map[string]string{}
  189. reply = &types.Reply{Data: res}
  190. in.Name = strings.TrimSpace(in.Name)
  191. if in.Name == "" {
  192. return
  193. }
  194. pageSize := 10
  195. if in.Type == "adiffb" {
  196. probusfors := NetworkCom.GetMyProbusfor(in.EntAccountId)
  197. if len(probusfors) > 0 {
  198. args := []interface{}{in.EntName}
  199. wh, newArgs := NetworkCom.WhArgs(probusfors)
  200. args = append(args, newArgs...)
  201. q := `select DISTINCT winner_id,winner from information.transaction_info where buyer_id in (select buyer_id from information.transaction_info where has(winner, ?) and buyer_id<>'') and hasAny(property_form,[` + wh + `])=0 ORDER BY project_id`
  202. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  203. if err != nil {
  204. logx.Error(err)
  205. } else {
  206. repeat := map[string]bool{}
  207. ids := []string{}
  208. for rows.Next() {
  209. var (
  210. winner_id []string
  211. winner []string
  212. )
  213. if err := rows.Scan(&winner_id, &winner); err != nil {
  214. logx.Error(err)
  215. continue
  216. }
  217. for k, v := range winner {
  218. if repeat[v] || !strings.Contains(v, in.Name) {
  219. continue
  220. }
  221. repeat[v] = true
  222. if k >= len(winner_id) {
  223. continue
  224. }
  225. ids = append(ids, winner_id[k])
  226. res = append(res, map[string]string{
  227. "company_name": v,
  228. "company_id": winner_id[k],
  229. })
  230. if len(res) == pageSize {
  231. break
  232. }
  233. }
  234. }
  235. rows.Close()
  236. if err := rows.Err(); err != nil {
  237. logx.Error(err)
  238. }
  239. qyxyId := n.GetQyxyId(ids)
  240. for _, v := range res {
  241. v["qyxy_id"] = qyxyId[v["company_id"]]
  242. }
  243. }
  244. }
  245. } else {
  246. must := []string{fmt.Sprintf(`{"multi_match":{"query":"%s","type":"phrase","fields":["company_name"]}}`, in.Name)}
  247. switch in.Type {
  248. case "firstparty":
  249. must = append(must, fmt.Sprintf(`{"terms":{"company_label":["%s"]}}`, strings.Join(NetworkCom.GetEntTagSeat(2), `","`)))
  250. must = append(must, `{"terms":{"company_unit_type":[1,2]}}`)
  251. case "supplier":
  252. must = append(must, fmt.Sprintf(`{"terms":{"company_label":["%s"]}}`, strings.Join(NetworkCom.GetEntTagSeat(2), `","`)))
  253. must = append(must, `{"term":{"company_unit_type":3}}`)
  254. case "middleman_owner":
  255. must = append(must, `{"terms":{"company_unit_type":[1,2]}}`)
  256. case "agency":
  257. must = append(must, `{"term":{"company_unit_type":4}}`)
  258. }
  259. q := fmt.Sprintf(`{"query":{"bool":{"must":[%s]}},"size":%d,"_source":["id","company_id","company_name"]}`, strings.Join(must, ","), pageSize)
  260. logx.Info("人脉库-业主名称联想", q)
  261. datas := VarEs.Get("ent_info", "ent_info", q)
  262. if datas != nil {
  263. for _, v := range *datas {
  264. res = append(res, map[string]string{
  265. "company_name": ObjToString(v["company_name"]),
  266. "company_id": ObjToString(v["id"]),
  267. "qyxy_id": ObjToString(v["company_id"]),
  268. })
  269. }
  270. }
  271. }
  272. reply.Data = res
  273. return
  274. }
  275. //人脉库-全部人脉项目
  276. func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
  277. reply = &types.Reply{}
  278. probusfors := NetworkCom.GetMyProbusfor(in.EntAccountId)
  279. var count int64
  280. var list []*networkTree
  281. firstpartyChild := map[string][]*firstpartyNetwork{}
  282. if in.Id != "" {
  283. if in.Type == "firstparty" {
  284. fpn := n.FirstpartyNetwork(in.Name, []string{in.Id})
  285. if fpn[in.Id] != nil {
  286. firstparty := n.Introduce_Firstparty(fpn, map[string]bool{}, probusfors)
  287. nameIndex := map[string]int{}
  288. for _, v := range fpn[in.Id] {
  289. if _, ok := nameIndex[v.Name]; !ok {
  290. nameIndex[v.Name] = len(list)
  291. list = append(list, &networkTree{
  292. Name: v.Name,
  293. })
  294. }
  295. ntc := &networkTreeChild{
  296. CompanyName: v.CompanyName,
  297. CompanyId: v.CompanyId,
  298. Type: "firstparty",
  299. }
  300. if firstparty[v.CompanyId] != nil {
  301. ntc.Count = firstparty[v.CompanyId].ProjectCount
  302. }
  303. count++
  304. list[nameIndex[v.Name]].Count += ntc.Count
  305. list[nameIndex[v.Name]].Children = append(list[nameIndex[v.Name]].Children, ntc)
  306. }
  307. }
  308. }
  309. } else {
  310. args := []interface{}{in.PositionId, in.PositionId, in.PositionId}
  311. sqlAppend1 := ""
  312. if in.Name != "" {
  313. sqlAppend1 += ` and a.company_name like ?`
  314. args = append(args, "%"+in.Name+"%")
  315. }
  316. aio := n.AllIntroduceOwner(sqlAppend1, "", args, true, probusfors, map[string]bool{})
  317. firstpartyChild = aio.FirstpartyNetwork
  318. list = []*networkTree{
  319. &networkTree{
  320. Name: "甲方",
  321. Children: []*networkTreeChild{},
  322. },
  323. &networkTree{
  324. Name: "供应商",
  325. Children: []*networkTreeChild{},
  326. },
  327. &networkTree{
  328. Name: "同甲异业渠道",
  329. Children: []*networkTreeChild{},
  330. },
  331. &networkTree{
  332. Name: "中间人",
  333. Children: []*networkTreeChild{},
  334. },
  335. &networkTree{
  336. Name: "招标代理",
  337. Children: []*networkTreeChild{},
  338. },
  339. }
  340. //
  341. for _, v := range aio.Networks {
  342. if v.Itype <= 0 || v.Itype > int64(len(list)) {
  343. return
  344. }
  345. ntc := &networkTreeChild{
  346. Id: v.Id,
  347. CompanyName: v.Company_name,
  348. CompanyId: v.Company_id,
  349. Type: n.TypeIntConvert(v.Itype),
  350. CreateTime: v.Create_time,
  351. }
  352. switch v.Itype {
  353. case 1:
  354. if aio.Firstparty[v.Company_id] != nil {
  355. ntc.Count = aio.Firstparty[v.Company_id].ProjectCount
  356. }
  357. case 2:
  358. if aio.Supplier[v.Company_id] != nil {
  359. ntc.Count = aio.Supplier[v.Company_id].ProjectCount
  360. }
  361. case 3:
  362. if aio.Adiffb[v.Company_id] != nil {
  363. ntc.Count = aio.Adiffb[v.Company_id].ProjectCount
  364. }
  365. case 4:
  366. if v.Relate_project_id != "" {
  367. for _, v := range strings.Split(v.Relate_project_id, ",") {
  368. if aio.Middleman[v] != nil {
  369. ntc.Count++
  370. }
  371. }
  372. }
  373. case 5:
  374. if aio.Agency[v.Company_id] != nil {
  375. ntc.Count = aio.Agency[v.Company_id].ProjectCount
  376. }
  377. }
  378. count += ntc.Count
  379. list[v.Itype-1].Count += ntc.Count
  380. list[v.Itype-1].Children = append(list[v.Itype-1].Children, ntc)
  381. }
  382. }
  383. convList := []map[string]interface{}{}
  384. for _, v := range list {
  385. pm := map[string]interface{}{
  386. "CODE": v.Name,
  387. "NAME": v.Name,
  388. "SZ_PID0": v.Name,
  389. "SZ_LEVEL": 0,
  390. "DATACOUNT": 0,
  391. }
  392. if len(v.Children) > 0 {
  393. pm["SZ_LEAF"] = 0
  394. } else {
  395. pm["SZ_LEAF"] = 1
  396. }
  397. sort.Sort(v)
  398. id := ""
  399. pType := ""
  400. for _, vv := range v.Children {
  401. tempId := vv.CompanyId
  402. if vv.Type == "middleman" {
  403. tempId = fmt.Sprint(vv.Id)
  404. }
  405. myChildIds, myChildTypes := "", ""
  406. if in.Id == "" && v.Name == "甲方" {
  407. for _, vvv := range firstpartyChild[vv.CompanyId] {
  408. if id != "" {
  409. id += ","
  410. }
  411. id += vvv.CompanyId
  412. if pType != "" {
  413. pType += ","
  414. }
  415. pType += vv.Type
  416. if myChildIds != "" {
  417. myChildIds += ","
  418. }
  419. myChildIds += vvv.CompanyId
  420. if myChildTypes != "" {
  421. myChildTypes += ","
  422. }
  423. myChildTypes += vv.Type
  424. }
  425. } else {
  426. if id != "" {
  427. id += ","
  428. }
  429. id += tempId
  430. if pType != "" {
  431. pType += ","
  432. }
  433. pType += vv.Type
  434. myChildIds = tempId
  435. myChildTypes = vv.Type
  436. }
  437. cm := map[string]interface{}{
  438. "NAME": vv.CompanyName,
  439. "ID": myChildIds,
  440. "SZ_PID0": v.Name,
  441. "SZ_PID1": v.Name + ":" + tempId,
  442. "CODE": v.Name + ":" + tempId,
  443. "PCODE": v.Name,
  444. "DATACOUNT": vv.Count,
  445. "SZ_LEVEL": 1,
  446. "SZ_LEAF": 1,
  447. "TYPE": myChildTypes,
  448. "MYID": tempId,
  449. }
  450. convList = append(convList, cm)
  451. }
  452. pm["ID"] = id
  453. pm["TYPE"] = pType
  454. convList = append(convList, pm)
  455. }
  456. reply = &types.Reply{
  457. Data: map[string]interface{}{
  458. "count": count,
  459. "list": convList,
  460. },
  461. }
  462. return reply
  463. }
  464. //人脉库-列表
  465. func (n *network) List(in *types.NetWorkListReq) *types.Reply {
  466. if in.Page_size <= 0 {
  467. in.Page_size = 10
  468. }
  469. if in.Current_page <= 0 {
  470. in.Current_page = 1
  471. }
  472. sqlAppendArgs := []interface{}{}
  473. sqlAppend1 := ""
  474. if in.Type != "" {
  475. sqlAppend1 += ` and a.itype=?`
  476. sqlAppendArgs = append(sqlAppendArgs, n.TypeStrConvert(in.Type))
  477. }
  478. if in.Starttime != "" {
  479. sqlAppend1 += ` and a.create_time>=?`
  480. sqlAppendArgs = append(sqlAppendArgs, in.Starttime+" 00:00:00")
  481. }
  482. if in.Endtime != "" {
  483. sqlAppend1 += ` and a.create_time<=?`
  484. if in.Starttime == in.Endtime {
  485. in.Endtime += " 23:59:59"
  486. } else {
  487. in.Endtime += " 00:00:00"
  488. }
  489. sqlAppendArgs = append(sqlAppendArgs, in.Endtime)
  490. }
  491. if in.Name != "" {
  492. sqlAppend1 += ` and a.company_name like ?`
  493. sqlAppendArgs = append(sqlAppendArgs, "%"+in.Name+"%")
  494. }
  495. var count int64
  496. start := (in.Current_page - 1) * in.Page_size
  497. end := start + in.Page_size
  498. dbPaging := in.Buyercount_start == 0 && in.Buyercount_end == 0 && in.Monitor == 0 && in.Monitorcount_start == 0 && in.Monitorcount_end == 0 && in.Project_matchme == 0 && in.Order_amount == 0
  499. args := []interface{}{in.PositionId, in.PositionId, in.PositionId}
  500. args = append(args, sqlAppendArgs...)
  501. sqlAppend2 := ""
  502. firstparty_count, supplier_count, adiffb_count, middleman_count, agency_count := 0, 0, 0, 0, 0
  503. if dbPaging {
  504. newArgs := []interface{}{in.PositionId}
  505. newArgs = append(newArgs, sqlAppendArgs...)
  506. count = CrmMysql.CountBySql(`select count(1) as count from crm.connection a where a.position_id=?`+sqlAppend1, newArgs...)
  507. sqlAppend2 = ` limit ?,?`
  508. args = append(args, start, end)
  509. items := CrmMysql.SelectBySql(`SELECT itype,SUM(1) AS sum FROM crm.connection WHERE position_id=?`+sqlAppend1+` GROUP BY itype`, newArgs...)
  510. if items != nil {
  511. for _, v := range *items {
  512. switch Int64All(v["itype"]) {
  513. case 1:
  514. firstparty_count = IntAll(v["sum"])
  515. case 2:
  516. supplier_count = IntAll(v["sum"])
  517. case 3:
  518. adiffb_count = IntAll(v["sum"])
  519. case 4:
  520. middleman_count = IntAll(v["sum"])
  521. case 5:
  522. agency_count = IntAll(v["sum"])
  523. }
  524. }
  525. }
  526. }
  527. //
  528. list := []*map[string]interface{}{}
  529. isTjProject := true
  530. probusfors := []string{}
  531. if in.Project_matchme == 1 {
  532. probusfors = NetworkCom.GetMyProbusfor(in.EntAccountId)
  533. if len(probusfors) == 0 {
  534. isTjProject = false
  535. }
  536. }
  537. if isTjProject {
  538. entMonitor := NetworkCom.EntMonitor(in.UserId)
  539. log.Println(entMonitor)
  540. aio := n.AllIntroduceOwner(sqlAppend1, sqlAppend2, args, isTjProject, probusfors, entMonitor)
  541. for _, v := range aio.Networks {
  542. itype := ""
  543. buyer_count, project_count, expect_amount, monitor_count := int64(0), int64(0), float64(0), int64(0)
  544. export_id := []string{}
  545. jump_type, jump_id := "", ""
  546. switch v.Itype {
  547. case 1:
  548. itype = "甲方"
  549. jump_type = "firstparty"
  550. for _, vv := range aio.FirstpartyNetwork[v.Company_id] {
  551. if jump_id != "" {
  552. jump_id += ","
  553. }
  554. jump_id += vv.CompanyId
  555. }
  556. if aio.Firstparty[v.Company_id] != nil {
  557. buyer_count = aio.Firstparty[v.Company_id].BuyerCount
  558. project_count = aio.Firstparty[v.Company_id].ProjectCount
  559. expect_amount = aio.Firstparty[v.Company_id].ProjectAmount
  560. monitor_count = aio.Firstparty[v.Company_id].MonitorCount
  561. export_id = aio.Firstparty[v.Company_id].ExportId
  562. }
  563. case 2:
  564. itype = "供应商"
  565. jump_type = "supplier"
  566. jump_id = v.Company_id
  567. if aio.Supplier[v.Company_id] != nil {
  568. buyer_count = aio.Supplier[v.Company_id].BuyerCount
  569. project_count = aio.Supplier[v.Company_id].ProjectCount
  570. expect_amount = aio.Supplier[v.Company_id].ProjectAmount
  571. monitor_count = aio.Supplier[v.Company_id].MonitorCount
  572. export_id = aio.Supplier[v.Company_id].ExportId
  573. }
  574. case 3:
  575. itype = "同甲异业渠道"
  576. jump_type = "adiffb"
  577. jump_id = v.Company_id
  578. if aio.Adiffb[v.Company_id] != nil {
  579. buyer_count = aio.Adiffb[v.Company_id].BuyerCount
  580. project_count = aio.Adiffb[v.Company_id].ProjectCount
  581. expect_amount = aio.Adiffb[v.Company_id].ProjectAmount
  582. monitor_count = aio.Adiffb[v.Company_id].MonitorCount
  583. export_id = aio.Adiffb[v.Company_id].ExportId
  584. }
  585. case 4:
  586. itype = "中间人"
  587. jump_type = "middleman"
  588. jump_id = fmt.Sprint(v.Id)
  589. buyer_count = v.Buyer_count
  590. if v.Relate_buyer_id != "" {
  591. for _, v := range strings.Split(v.Relate_buyer_id, ",") {
  592. if v == "" {
  593. continue
  594. }
  595. if entMonitor[v] {
  596. monitor_count++
  597. }
  598. }
  599. }
  600. if v.Relate_project_id != "" {
  601. export_id = strings.Split(v.Relate_project_id, ",")
  602. for _, v := range export_id {
  603. if aio.Middleman[v] != nil {
  604. project_count++
  605. expect_amount += aio.Middleman[v].ProjectAmount
  606. }
  607. }
  608. }
  609. case 5:
  610. itype = "招标代理机构"
  611. jump_type = "agency"
  612. jump_id = v.Company_id
  613. if aio.Agency[v.Company_id] != nil {
  614. buyer_count = aio.Agency[v.Company_id].BuyerCount
  615. project_count = aio.Agency[v.Company_id].ProjectCount
  616. expect_amount = aio.Agency[v.Company_id].ProjectAmount
  617. monitor_count = aio.Agency[v.Company_id].MonitorCount
  618. export_id = aio.Agency[v.Company_id].ExportId
  619. }
  620. }
  621. if buyer_count < in.Buyercount_start {
  622. continue
  623. } else if in.Buyercount_end > 0 && buyer_count > in.Buyercount_end {
  624. continue
  625. } else if in.Monitor == 1 && monitor_count <= 0 {
  626. continue
  627. } else if in.Monitor == -1 && monitor_count > 0 {
  628. continue
  629. } else if monitor_count < in.Monitorcount_start {
  630. continue
  631. } else if in.Monitorcount_end > 0 && monitor_count > in.Monitorcount_end {
  632. continue
  633. } else if in.Project_matchme == 1 && project_count == 0 {
  634. continue
  635. }
  636. if !dbPaging {
  637. switch v.Itype {
  638. case 1:
  639. firstparty_count++
  640. case 2:
  641. supplier_count++
  642. case 3:
  643. adiffb_count++
  644. case 4:
  645. middleman_count++
  646. case 5:
  647. agency_count++
  648. }
  649. }
  650. export_url := ""
  651. if len(export_id) > 0 {
  652. exportIdRepeat := map[string]bool{}
  653. exportId := ""
  654. for _, v := range export_id {
  655. if exportIdRepeat[v] {
  656. continue
  657. }
  658. exportIdRepeat[v] = true
  659. if exportId != "" {
  660. exportId += ","
  661. }
  662. exportId += v
  663. }
  664. export_url = "/subscribepay/network/projectExport?export_id=" + encrypt.SE.EncodeStringByCheck(exportId)
  665. }
  666. url := ""
  667. if v.Qyxy_id != "" && (jump_type == "supplier" || jump_type == "adiffb") {
  668. url = "/swordfish/page_big_pc/ent_portrait/" + encrypt.EncodeArticleId2ByCheck(v.Qyxy_id)
  669. } else if jump_type == "firstparty" && v.Company_name != "" {
  670. url = "/swordfish/page_big_pc/unit_portrayal/" + v.Company_name
  671. }
  672. list = append(list, &map[string]interface{}{
  673. "company_id": v.Company_id,
  674. "company_name": v.Company_name,
  675. "type": itype,
  676. "jump_type": jump_type,
  677. "jump_id": jump_id,
  678. "person": v.Person,
  679. "phone": v.Phone,
  680. "buyer_count": buyer_count,
  681. "monitor_count": monitor_count,
  682. "expect_amount": RetainDecimal(expect_amount/10000, 2),
  683. "project_count": project_count,
  684. "create_time": v.Create_time,
  685. "export_url": export_url,
  686. "url": url,
  687. "id": v.Id,
  688. })
  689. }
  690. }
  691. csList := &ComSortList{
  692. SortKeys: []*ComSortKey{
  693. &ComSortKey{
  694. Keys: []string{"expect_amount"},
  695. Order: 1,
  696. Type: "float",
  697. },
  698. },
  699. List: list,
  700. }
  701. if in.Order_amount == -1 {
  702. csList.SortKeys[0].Order = -1
  703. }
  704. if in.Order_amount != 0 {
  705. sort.Sort(csList)
  706. }
  707. finalList := []*map[string]interface{}{}
  708. if !dbPaging {
  709. count = int64(len(csList.List))
  710. if count > 0 && start < count {
  711. if end > count {
  712. end = count
  713. }
  714. finalList = csList.List[start:end]
  715. }
  716. } else {
  717. finalList = csList.List
  718. }
  719. total_page := int64(math.Ceil(float64(count) / float64(in.Page_size)))
  720. return &types.Reply{
  721. Data: map[string]interface{}{
  722. "count": count,
  723. "total_page": total_page,
  724. "firstparty_count": firstparty_count,
  725. "supplier_count": supplier_count,
  726. "adiffb_count": adiffb_count,
  727. "middleman_count": middleman_count,
  728. "agency_count": agency_count,
  729. "list": finalList,
  730. },
  731. }
  732. }
  733. //
  734. func (n *network) FirstpartyNetwork(name string, values []string) map[string][]*firstpartyNetwork {
  735. result := map[string][]*firstpartyNetwork{}
  736. wh, args := NetworkCom.WhArgs(values)
  737. q := `select DISTINCT a.a_id,a.b_id as company_id,a.b_name as company_name,b.name from information.ent_map_code a
  738. inner join information.ent_code b on (a.a_id in (` + wh + `) and b.pcode in ('0100','0200') and a.code=b.code)`
  739. if name != "" {
  740. q += ` where c.company_name like ?`
  741. args = append(args, "%"+name+"%")
  742. }
  743. q += ` order by b.name,a.a_id,a.b_name`
  744. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  745. if err != nil {
  746. logx.Error(err)
  747. return result
  748. }
  749. for rows.Next() {
  750. var (
  751. a_id string
  752. company_id string
  753. company_name string
  754. name string
  755. )
  756. if err := rows.Scan(&a_id, &company_id, &company_name, &name); err != nil {
  757. logx.Error(err)
  758. continue
  759. }
  760. if company_id == "" || company_name == "" {
  761. continue
  762. }
  763. result[a_id] = append(result[a_id], &firstpartyNetwork{
  764. CompanyId: company_id,
  765. CompanyName: company_name,
  766. Name: name,
  767. })
  768. }
  769. return result
  770. }
  771. //
  772. func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
  773. values := []string{}
  774. vm := map[string]*projectInfo{}
  775. for _, v := range fpn {
  776. for _, vv := range v {
  777. vm[vv.CompanyId] = &projectInfo{}
  778. values = append(values, vv.CompanyId)
  779. }
  780. }
  781. result := map[string]*projectInfo{}
  782. if len(values) == 0 {
  783. return result
  784. }
  785. wh, args := NetworkCom.WhArgs(values)
  786. q := `select buyer_id,count(project_id) AS project_count,sum(project_money) AS project_amount,groupUniqArray(project_id) from information.transaction_info where buyer_id in (` + wh + `)`
  787. if len(probusfors) > 0 {
  788. newWh, newArgs := NetworkCom.WhArgs(probusfors)
  789. q += ` and hasAny(property_form,[` + newWh + `])`
  790. args = append(args, newArgs...)
  791. }
  792. q += ` group by buyer_id`
  793. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  794. if err != nil {
  795. logx.Error(err)
  796. return nil
  797. }
  798. for rows.Next() {
  799. var (
  800. buyer_id string
  801. project_count uint64
  802. project_amount decimal.Decimal
  803. project_id []string
  804. )
  805. if err := rows.Scan(&buyer_id, &project_count, &project_amount, &project_id); err != nil {
  806. logx.Error(err)
  807. continue
  808. }
  809. if vm[buyer_id] == nil {
  810. continue
  811. }
  812. vm[buyer_id].ProjectCount += int64(project_count)
  813. pf, _ := project_amount.Float64()
  814. vm[buyer_id].ProjectAmount += pf
  815. vm[buyer_id].ExportId = project_id
  816. }
  817. rows.Close()
  818. if err := rows.Err(); err != nil {
  819. logx.Error(err)
  820. }
  821. for k, v := range fpn {
  822. if result[k] == nil {
  823. result[k] = &projectInfo{}
  824. }
  825. result[k].BuyerCount = int64(len(v))
  826. for _, vv := range v {
  827. if entMonitor[vv.CompanyName] {
  828. result[k].MonitorCount++
  829. }
  830. if vm[vv.CompanyId] == nil {
  831. continue
  832. }
  833. result[k].ProjectCount += vm[vv.CompanyId].ProjectCount
  834. result[k].ProjectAmount += vm[vv.CompanyId].ProjectAmount
  835. result[k].ExportId = append(result[k].ExportId, vm[vv.CompanyId].ExportId...)
  836. }
  837. }
  838. return result
  839. }
  840. //
  841. func (n *network) Introduce_Supplier(values []string, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
  842. if len(values) == 0 {
  843. return map[string]*projectInfo{}
  844. }
  845. wh, args := NetworkCom.WhArgs(values)
  846. vbs := map[string][]*idName{}
  847. repeat := map[string]bool{}
  848. whRepeat := map[string]map[string]bool{}
  849. buyers := []string{}
  850. q := `select winner_id,buyer_id,buyer from information.transaction_info where hasAny(winner_id,[` + wh + `])`
  851. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  852. if err != nil {
  853. logx.Error(err)
  854. } else {
  855. for rows.Next() {
  856. var (
  857. winner_id []string
  858. buyer_id string
  859. buyer string
  860. )
  861. if err := rows.Scan(&winner_id, &buyer_id, &buyer); err != nil {
  862. logx.Error(err)
  863. continue
  864. }
  865. if buyer_id == "" || buyer == "" {
  866. continue
  867. }
  868. if !repeat[buyer_id] {
  869. repeat[buyer_id] = true
  870. buyers = append(buyers, buyer_id)
  871. }
  872. for _, v := range winner_id {
  873. if whRepeat[v] != nil && whRepeat[v][buyer_id] {
  874. continue
  875. }
  876. if whRepeat[v] == nil {
  877. whRepeat[v] = map[string]bool{}
  878. }
  879. whRepeat[v][buyer_id] = true
  880. vbs[v] = append(vbs[v], &idName{
  881. Id: buyer_id,
  882. Name: buyer,
  883. })
  884. }
  885. }
  886. rows.Close()
  887. if err := rows.Err(); err != nil {
  888. logx.Error(err)
  889. }
  890. }
  891. return n.MakeProjectInfo(buyers, vbs, probusfors, entMonitor)
  892. }
  893. //
  894. func (n *network) Introduce_Agency(values []string, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
  895. if len(values) == 0 {
  896. return map[string]*projectInfo{}
  897. }
  898. wh, args := NetworkCom.WhArgs(values)
  899. q := `select DISTINCT agency_id,buyer_id,buyer from information.transaction_info where agency_id in (` + wh + `)`
  900. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  901. if err != nil {
  902. logx.Error(err)
  903. return nil
  904. }
  905. vbs := map[string][]*idName{}
  906. buyers := []string{}
  907. repeat := map[string]bool{}
  908. for rows.Next() {
  909. var (
  910. agency_id string
  911. buyer_id string
  912. buyer string
  913. )
  914. if err := rows.Scan(&agency_id, &buyer_id, &buyer); err != nil {
  915. logx.Error(err)
  916. continue
  917. }
  918. if buyer_id == "" || buyer == "" {
  919. continue
  920. }
  921. vbs[agency_id] = append(vbs[agency_id], &idName{
  922. Id: buyer_id,
  923. Name: buyer,
  924. })
  925. if !repeat[buyer_id] {
  926. repeat[buyer_id] = true
  927. buyers = append(buyers, buyer_id)
  928. }
  929. }
  930. rows.Close()
  931. if err := rows.Err(); err != nil {
  932. logx.Error(err)
  933. }
  934. return n.MakeProjectInfo(buyers, vbs, probusfors, entMonitor)
  935. }
  936. //
  937. func (n *network) Introduce_Middleman(values []string, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
  938. result := map[string]*projectInfo{}
  939. if len(values) == 0 {
  940. return result
  941. }
  942. wh, args := NetworkCom.WhArgs(values)
  943. q := `select DISTINCT project_id,project_money from information.transaction_info where project_id in (` + wh + `)`
  944. if len(probusfors) > 0 {
  945. newWh, newArgs := NetworkCom.WhArgs(probusfors)
  946. q += ` and hasAny(property_form,[` + newWh + `])`
  947. args = append(args, newArgs...)
  948. }
  949. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  950. if err != nil {
  951. logx.Error(err)
  952. return nil
  953. }
  954. for rows.Next() {
  955. var (
  956. project_id string
  957. project_money decimal.Decimal
  958. )
  959. if err := rows.Scan(&project_id, &project_money); err != nil {
  960. logx.Error(err)
  961. continue
  962. }
  963. pf, _ := project_money.Float64()
  964. result[project_id] = &projectInfo{
  965. ProjectAmount: pf,
  966. }
  967. }
  968. rows.Close()
  969. if err := rows.Err(); err != nil {
  970. logx.Error(err)
  971. }
  972. return result
  973. }
  974. //
  975. func (n *network) TypeStrConvert(itype string) int {
  976. //firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构
  977. switch itype {
  978. case "firstparty":
  979. return 1
  980. case "supplier":
  981. return 2
  982. case "adiffb":
  983. return 3
  984. case "middleman":
  985. return 4
  986. case "agency":
  987. return 5
  988. }
  989. return 0
  990. }
  991. //
  992. func (n *network) TypeIntConvert(itype int64) string {
  993. //firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构
  994. switch itype {
  995. case 1:
  996. return "firstparty"
  997. case 2:
  998. return "supplier"
  999. case 3:
  1000. return "adiffb"
  1001. case 4:
  1002. return "middleman"
  1003. case 5:
  1004. return "agency"
  1005. }
  1006. return ""
  1007. }
  1008. //
  1009. func (n *network) GetQyxyId(ids []string) map[string]string {
  1010. wh, args := NetworkCom.WhArgs(ids)
  1011. q := `select id,company_id from information.ent_info where id in (` + wh + `)`
  1012. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  1013. m := map[string]string{}
  1014. if err != nil {
  1015. logx.Error(err)
  1016. } else {
  1017. for rows.Next() {
  1018. var (
  1019. id string
  1020. company_id string
  1021. )
  1022. if err := rows.Scan(&id, &company_id); err != nil {
  1023. logx.Error(err)
  1024. continue
  1025. }
  1026. m[id] = company_id
  1027. }
  1028. rows.Close()
  1029. if err := rows.Err(); err != nil {
  1030. logx.Error(err)
  1031. }
  1032. }
  1033. return m
  1034. }
  1035. //
  1036. func (n *network) BuyerProjectInfo(ids []string, probusfors []string) map[string]*projectInfo {
  1037. vm := map[string]*projectInfo{}
  1038. wh, args := NetworkCom.WhArgs(ids)
  1039. q := `select buyer_id,count(DISTINCT project_id) AS project_count,sum(project_money) AS project_amount,groupUniqArray(project_id) from information.transaction_info where buyer_id in (` + wh + `)`
  1040. if len(probusfors) > 0 {
  1041. newWh, newArgs := NetworkCom.WhArgs(probusfors)
  1042. q += ` and hasAny(property_form,[` + newWh + `])`
  1043. args = append(args, newArgs...)
  1044. }
  1045. q += ` group by buyer_id`
  1046. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  1047. if err != nil {
  1048. logx.Error(err)
  1049. return nil
  1050. }
  1051. for rows.Next() {
  1052. var (
  1053. buyer_id string
  1054. project_count uint64
  1055. project_amount decimal.Decimal
  1056. project_id []string
  1057. )
  1058. if err := rows.Scan(&buyer_id, &project_count, &project_amount, &project_id); err != nil {
  1059. logx.Error(err)
  1060. continue
  1061. }
  1062. pf, _ := project_amount.Float64()
  1063. vm[buyer_id] = &projectInfo{
  1064. ProjectCount: int64(project_count),
  1065. ExportId: project_id,
  1066. ProjectAmount: pf,
  1067. }
  1068. }
  1069. rows.Close()
  1070. if err := rows.Err(); err != nil {
  1071. logx.Error(err)
  1072. }
  1073. return vm
  1074. }
  1075. //
  1076. func (n *network) MakeProjectInfo(buyers []string, vbs map[string][]*idName, probusfors []string, entMonitor map[string]bool) map[string]*projectInfo {
  1077. pis := n.BuyerProjectInfo(buyers, probusfors)
  1078. vm := map[string]*projectInfo{}
  1079. for k, v := range vbs {
  1080. pi := &projectInfo{
  1081. BuyerCount: int64(len(v)),
  1082. }
  1083. re := map[string]bool{}
  1084. for _, vv := range v {
  1085. if pis[vv.Id] != nil {
  1086. pi.ProjectCount += pis[vv.Id].ProjectCount
  1087. pi.ProjectAmount += pis[vv.Id].ProjectAmount
  1088. for _, vvv := range pis[vv.Id].ExportId {
  1089. if re[vvv] {
  1090. continue
  1091. }
  1092. pi.ExportId = append(pi.ExportId, vvv)
  1093. re[vvv] = true
  1094. }
  1095. }
  1096. if entMonitor[vv.Name] {
  1097. pi.MonitorCount++
  1098. }
  1099. }
  1100. vm[k] = pi
  1101. }
  1102. return vm
  1103. }
  1104. //
  1105. func (n *network) AllIntroduceOwner(sqlAppend1, sqlAppend2 string, args []interface{}, isTjProject bool, probusfors []string, entMonitor map[string]bool) *introduceOwnerProject {
  1106. q := `select a.id,a.company_id,a.company_name,a.qyxy_id,a.itype,a.contact_person as person,a.contact_phone as phone,count(DISTINCT if(b.itype=1,b.relate_id,null)) as buyer_count,count(DISTINCT if(b.itype=2,b.relate_id,null)) as project_count,GROUP_CONCAT(IF(b.itype=1,b.relate_id,NULL)) AS relate_buyer_id,GROUP_CONCAT(IF(b.itype=2,b.relate_id,NULL)) AS relate_project_id,a.create_time from crm.connection a
  1107. left join crm.connection_introduce b on (a.position_id=? and b.position_id=? and a.id=b.connection_id) where a.position_id=?` + sqlAppend1 + ` GROUP BY a.id order by a.create_time desc` + sqlAppend2
  1108. listTemp := CrmMysql.SelectBySql(q, args...)
  1109. firstparty_array, supplier_array, adiffb_array, agency_array, middleman_project_array := []string{}, []string{}, []string{}, []string{}, []string{}
  1110. myNetworks := []*myNetwork{}
  1111. for _, v := range *listTemp {
  1112. myNetwork := &myNetwork{
  1113. Id: Int64All(v["id"]),
  1114. Company_id: ObjToString(v["company_id"]),
  1115. Company_name: ObjToString(v["company_name"]),
  1116. Qyxy_id: ObjToString(v["qyxy_id"]),
  1117. Itype: Int64All(v["itype"]),
  1118. Person: ObjToString(v["person"]),
  1119. Phone: ObjToString(v["phone"]),
  1120. Buyer_count: Int64All(v["buyer_count"]),
  1121. Project_count: Int64All(v["project_count"]),
  1122. Relate_buyer_id: ObjToString(v["relate_buyer_id"]),
  1123. Relate_project_id: ObjToString(v["relate_project_id"]),
  1124. Create_time: ObjToString(v["create_time"]),
  1125. }
  1126. switch myNetwork.Itype {
  1127. case 1:
  1128. firstparty_array = append(firstparty_array, myNetwork.Company_id)
  1129. case 2:
  1130. supplier_array = append(supplier_array, myNetwork.Company_id)
  1131. case 3:
  1132. adiffb_array = append(adiffb_array, myNetwork.Company_id)
  1133. case 4:
  1134. if myNetwork.Relate_project_id != "" {
  1135. middleman_project_array = append(middleman_project_array, strings.Split(myNetwork.Relate_project_id, ",")...)
  1136. }
  1137. case 5:
  1138. agency_array = append(agency_array, myNetwork.Company_id)
  1139. }
  1140. myNetworks = append(myNetworks, myNetwork)
  1141. }
  1142. iop := &introduceOwnerProject{
  1143. Networks: myNetworks,
  1144. FirstpartyNetwork: map[string][]*firstpartyNetwork{},
  1145. Firstparty: map[string]*projectInfo{},
  1146. Supplier: map[string]*projectInfo{},
  1147. Adiffb: map[string]*projectInfo{},
  1148. Agency: map[string]*projectInfo{},
  1149. Middleman: map[string]*projectInfo{},
  1150. }
  1151. if isTjProject {
  1152. iop.FirstpartyNetwork = n.FirstpartyNetwork("", firstparty_array)
  1153. iop.Firstparty = n.Introduce_Firstparty(iop.FirstpartyNetwork, entMonitor, probusfors)
  1154. iop.Supplier = n.Introduce_Supplier(supplier_array, entMonitor, probusfors)
  1155. iop.Adiffb = n.Introduce_Supplier(adiffb_array, entMonitor, probusfors)
  1156. iop.Agency = n.Introduce_Agency(agency_array, entMonitor, probusfors)
  1157. iop.Middleman = n.Introduce_Middleman(middleman_project_array, entMonitor, probusfors)
  1158. }
  1159. return iop
  1160. }