network.go 35 KB

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