network.go 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  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. wh, args := NetworkCom.WhArgs(values)
  756. 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
  757. inner join information.ent_code b on (a.a_id in (` + wh + `) and b.pcode in ('0100','0200') and a.code=b.code)`
  758. if name != "" {
  759. q += ` where c.company_name like ?`
  760. args = append(args, "%"+name+"%")
  761. }
  762. q += ` order by b.name,a.a_id,a.b_name`
  763. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  764. if err != nil {
  765. logx.Error(err)
  766. return result
  767. }
  768. for rows.Next() {
  769. var (
  770. a_id string
  771. company_id string
  772. company_name string
  773. name string
  774. )
  775. if err := rows.Scan(&a_id, &company_id, &company_name, &name); err != nil {
  776. logx.Error(err)
  777. continue
  778. }
  779. if company_id == "" || company_name == "" {
  780. continue
  781. }
  782. result[a_id] = append(result[a_id], &firstpartyNetwork{
  783. CompanyId: company_id,
  784. CompanyName: company_name,
  785. Name: name,
  786. })
  787. }
  788. return result
  789. }
  790. //
  791. func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
  792. values := []string{}
  793. vm := map[string]*projectInfo{}
  794. for _, v := range fpn {
  795. for _, vv := range v {
  796. vm[vv.CompanyId] = &projectInfo{}
  797. values = append(values, vv.CompanyId)
  798. }
  799. }
  800. result := map[string]*projectInfo{}
  801. if len(values) == 0 {
  802. return result
  803. }
  804. wh, args := NetworkCom.WhArgs(values)
  805. 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 + `)`
  806. if len(probusfors) > 0 {
  807. newWh, newArgs := NetworkCom.WhArgs(probusfors)
  808. q += ` and hasAny(property_form,[` + newWh + `])`
  809. args = append(args, newArgs...)
  810. }
  811. q += ` group by buyer_id`
  812. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  813. if err != nil {
  814. logx.Error(err)
  815. return nil
  816. }
  817. for rows.Next() {
  818. var (
  819. buyer_id string
  820. project_count uint64
  821. project_amount decimal.Decimal
  822. project_id []string
  823. )
  824. if err := rows.Scan(&buyer_id, &project_count, &project_amount, &project_id); err != nil {
  825. logx.Error(err)
  826. continue
  827. }
  828. if vm[buyer_id] == nil {
  829. continue
  830. }
  831. vm[buyer_id].ProjectCount += int64(project_count)
  832. pf, _ := project_amount.Float64()
  833. vm[buyer_id].ProjectAmount += pf
  834. vm[buyer_id].ExportId = project_id
  835. }
  836. rows.Close()
  837. if err := rows.Err(); err != nil {
  838. logx.Error(err)
  839. }
  840. for k, v := range fpn {
  841. if result[k] == nil {
  842. result[k] = &projectInfo{}
  843. }
  844. result[k].BuyerCount = int64(len(v))
  845. for _, vv := range v {
  846. log.Println(k, vv.CompanyName)
  847. if entMonitor[vv.CompanyName] {
  848. result[k].MonitorCount++
  849. }
  850. if vm[vv.CompanyId] == nil {
  851. continue
  852. }
  853. result[k].ProjectCount += vm[vv.CompanyId].ProjectCount
  854. result[k].ProjectAmount += vm[vv.CompanyId].ProjectAmount
  855. result[k].ExportId = append(result[k].ExportId, vm[vv.CompanyId].ExportId...)
  856. }
  857. }
  858. return result
  859. }
  860. //
  861. func (n *network) Introduce_Supplier(values []string, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
  862. if len(values) == 0 {
  863. return map[string]*projectInfo{}
  864. }
  865. wh, args := NetworkCom.WhArgs(values)
  866. vbs := map[string][]*idName{}
  867. repeat := map[string]bool{}
  868. whRepeat := map[string]map[string]bool{}
  869. buyers := []string{}
  870. q := `select winner_id,buyer_id,buyer from information.transaction_info where hasAny(winner_id,[` + wh + `])`
  871. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  872. if err != nil {
  873. logx.Error(err)
  874. } else {
  875. for rows.Next() {
  876. var (
  877. winner_id []string
  878. buyer_id string
  879. buyer string
  880. )
  881. if err := rows.Scan(&winner_id, &buyer_id, &buyer); err != nil {
  882. logx.Error(err)
  883. continue
  884. }
  885. if buyer_id == "" || buyer == "" {
  886. continue
  887. }
  888. if !repeat[buyer_id] {
  889. repeat[buyer_id] = true
  890. buyers = append(buyers, buyer_id)
  891. }
  892. for _, v := range winner_id {
  893. if whRepeat[v] != nil && whRepeat[v][buyer_id] {
  894. continue
  895. }
  896. if whRepeat[v] == nil {
  897. whRepeat[v] = map[string]bool{}
  898. }
  899. whRepeat[v][buyer_id] = true
  900. vbs[v] = append(vbs[v], &idName{
  901. Id: buyer_id,
  902. Name: buyer,
  903. })
  904. }
  905. }
  906. rows.Close()
  907. if err := rows.Err(); err != nil {
  908. logx.Error(err)
  909. }
  910. }
  911. return n.MakeProjectInfo(buyers, vbs, probusfors, entMonitor)
  912. }
  913. //
  914. func (n *network) Introduce_Agency(values []string, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
  915. if len(values) == 0 {
  916. return map[string]*projectInfo{}
  917. }
  918. wh, args := NetworkCom.WhArgs(values)
  919. q := `select DISTINCT agency_id,buyer_id,buyer from information.transaction_info where agency_id in (` + wh + `)`
  920. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  921. if err != nil {
  922. logx.Error(err)
  923. return nil
  924. }
  925. vbs := map[string][]*idName{}
  926. buyers := []string{}
  927. repeat := map[string]bool{}
  928. for rows.Next() {
  929. var (
  930. agency_id string
  931. buyer_id string
  932. buyer string
  933. )
  934. if err := rows.Scan(&agency_id, &buyer_id, &buyer); err != nil {
  935. logx.Error(err)
  936. continue
  937. }
  938. if buyer_id == "" || buyer == "" {
  939. continue
  940. }
  941. vbs[agency_id] = append(vbs[agency_id], &idName{
  942. Id: buyer_id,
  943. Name: buyer,
  944. })
  945. if !repeat[buyer_id] {
  946. repeat[buyer_id] = true
  947. buyers = append(buyers, buyer_id)
  948. }
  949. }
  950. rows.Close()
  951. if err := rows.Err(); err != nil {
  952. logx.Error(err)
  953. }
  954. return n.MakeProjectInfo(buyers, vbs, probusfors, entMonitor)
  955. }
  956. //
  957. func (n *network) Introduce_Middleman(values []string, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
  958. result := map[string]*projectInfo{}
  959. if len(values) == 0 {
  960. return result
  961. }
  962. wh, args := NetworkCom.WhArgs(values)
  963. q := `select DISTINCT project_id,project_money from information.transaction_info where project_id in (` + wh + `)`
  964. if len(probusfors) > 0 {
  965. newWh, newArgs := NetworkCom.WhArgs(probusfors)
  966. q += ` and hasAny(property_form,[` + newWh + `])`
  967. args = append(args, newArgs...)
  968. }
  969. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  970. if err != nil {
  971. logx.Error(err)
  972. return nil
  973. }
  974. for rows.Next() {
  975. var (
  976. project_id string
  977. project_money decimal.Decimal
  978. )
  979. if err := rows.Scan(&project_id, &project_money); err != nil {
  980. logx.Error(err)
  981. continue
  982. }
  983. pf, _ := project_money.Float64()
  984. result[project_id] = &projectInfo{
  985. ProjectAmount: pf,
  986. }
  987. }
  988. rows.Close()
  989. if err := rows.Err(); err != nil {
  990. logx.Error(err)
  991. }
  992. return result
  993. }
  994. //
  995. func (n *network) TypeStrConvert(itype string) int64 {
  996. //firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构
  997. switch itype {
  998. case "firstparty":
  999. return 1
  1000. case "supplier":
  1001. return 2
  1002. case "adiffb":
  1003. return 3
  1004. case "middleman":
  1005. return 4
  1006. case "agency":
  1007. return 5
  1008. }
  1009. return 0
  1010. }
  1011. //
  1012. func (n *network) TypeIntConvert(itype int64) string {
  1013. //firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构
  1014. switch itype {
  1015. case 1:
  1016. return "firstparty"
  1017. case 2:
  1018. return "supplier"
  1019. case 3:
  1020. return "adiffb"
  1021. case 4:
  1022. return "middleman"
  1023. case 5:
  1024. return "agency"
  1025. }
  1026. return ""
  1027. }
  1028. //
  1029. func (n *network) GetQyxyId(ids []string) map[string]string {
  1030. wh, args := NetworkCom.WhArgs(ids)
  1031. q := `select id,company_id from information.ent_info where id in (` + wh + `)`
  1032. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  1033. m := map[string]string{}
  1034. if err != nil {
  1035. logx.Error(err)
  1036. } else {
  1037. for rows.Next() {
  1038. var (
  1039. id string
  1040. company_id string
  1041. )
  1042. if err := rows.Scan(&id, &company_id); err != nil {
  1043. logx.Error(err)
  1044. continue
  1045. }
  1046. m[id] = company_id
  1047. }
  1048. rows.Close()
  1049. if err := rows.Err(); err != nil {
  1050. logx.Error(err)
  1051. }
  1052. }
  1053. return m
  1054. }
  1055. //
  1056. func (n *network) BuyerProjectInfo(ids []string, probusfors []string) map[string]*projectInfo {
  1057. vm := map[string]*projectInfo{}
  1058. wh, args := NetworkCom.WhArgs(ids)
  1059. 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 + `)`
  1060. if len(probusfors) > 0 {
  1061. newWh, newArgs := NetworkCom.WhArgs(probusfors)
  1062. q += ` and hasAny(property_form,[` + newWh + `])`
  1063. args = append(args, newArgs...)
  1064. }
  1065. q += ` group by buyer_id`
  1066. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  1067. if err != nil {
  1068. logx.Error(err)
  1069. return nil
  1070. }
  1071. for rows.Next() {
  1072. var (
  1073. buyer_id string
  1074. project_count uint64
  1075. project_amount decimal.Decimal
  1076. project_id []string
  1077. )
  1078. if err := rows.Scan(&buyer_id, &project_count, &project_amount, &project_id); err != nil {
  1079. logx.Error(err)
  1080. continue
  1081. }
  1082. pf, _ := project_amount.Float64()
  1083. vm[buyer_id] = &projectInfo{
  1084. ProjectCount: int64(project_count),
  1085. ExportId: project_id,
  1086. ProjectAmount: pf,
  1087. }
  1088. }
  1089. rows.Close()
  1090. if err := rows.Err(); err != nil {
  1091. logx.Error(err)
  1092. }
  1093. return vm
  1094. }
  1095. //
  1096. func (n *network) MakeProjectInfo(buyers []string, vbs map[string][]*idName, probusfors []string, entMonitor map[string]bool) map[string]*projectInfo {
  1097. pis := n.BuyerProjectInfo(buyers, probusfors)
  1098. vm := map[string]*projectInfo{}
  1099. for k, v := range vbs {
  1100. pi := &projectInfo{
  1101. BuyerCount: int64(len(v)),
  1102. }
  1103. re := map[string]bool{}
  1104. for _, vv := range v {
  1105. if pis[vv.Id] != nil {
  1106. pi.ProjectCount += pis[vv.Id].ProjectCount
  1107. pi.ProjectAmount += pis[vv.Id].ProjectAmount
  1108. for _, vvv := range pis[vv.Id].ExportId {
  1109. if re[vvv] {
  1110. continue
  1111. }
  1112. pi.ExportId = append(pi.ExportId, vvv)
  1113. re[vvv] = true
  1114. }
  1115. }
  1116. if entMonitor[vv.Name] {
  1117. pi.MonitorCount++
  1118. }
  1119. }
  1120. vm[k] = pi
  1121. }
  1122. return vm
  1123. }
  1124. //
  1125. func (n *network) AllIntroduceOwner(sqlAppend1, sqlAppend2 string, args []interface{}, isTjProject bool, probusfors []string, entMonitor map[string]bool) *introduceOwnerProject {
  1126. 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
  1127. 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
  1128. listTemp := CrmMysql.SelectBySql(q, args...)
  1129. firstparty_array, supplier_array, adiffb_array, agency_array, middleman_project_array := []string{}, []string{}, []string{}, []string{}, []string{}
  1130. myNetworks := []*myNetwork{}
  1131. for _, v := range *listTemp {
  1132. myNetwork := &myNetwork{
  1133. Id: Int64All(v["id"]),
  1134. Company_id: ObjToString(v["company_id"]),
  1135. Company_name: ObjToString(v["company_name"]),
  1136. Qyxy_id: ObjToString(v["qyxy_id"]),
  1137. Itype: Int64All(v["itype"]),
  1138. Person: ObjToString(v["person"]),
  1139. Phone: ObjToString(v["phone"]),
  1140. Buyer_count: Int64All(v["buyer_count"]),
  1141. Project_count: Int64All(v["project_count"]),
  1142. Relate_buyer_id: ObjToString(v["relate_buyer_id"]),
  1143. Relate_buyer_name: ObjToString(v["relate_buyer_name"]),
  1144. Relate_project_id: ObjToString(v["relate_project_id"]),
  1145. Create_time: ObjToString(v["create_time"]),
  1146. }
  1147. switch myNetwork.Itype {
  1148. case 1:
  1149. firstparty_array = append(firstparty_array, myNetwork.Company_id)
  1150. case 2:
  1151. supplier_array = append(supplier_array, myNetwork.Company_id)
  1152. case 3:
  1153. adiffb_array = append(adiffb_array, myNetwork.Company_id)
  1154. case 4:
  1155. if myNetwork.Relate_project_id != "" {
  1156. middleman_project_array = append(middleman_project_array, strings.Split(myNetwork.Relate_project_id, ",")...)
  1157. }
  1158. case 5:
  1159. agency_array = append(agency_array, myNetwork.Company_id)
  1160. }
  1161. myNetworks = append(myNetworks, myNetwork)
  1162. }
  1163. iop := &introduceOwnerProject{
  1164. Networks: myNetworks,
  1165. FirstpartyNetwork: map[string][]*firstpartyNetwork{},
  1166. Firstparty: map[string]*projectInfo{},
  1167. Supplier: map[string]*projectInfo{},
  1168. Adiffb: map[string]*projectInfo{},
  1169. Agency: map[string]*projectInfo{},
  1170. Middleman: map[string]*projectInfo{},
  1171. }
  1172. if isTjProject {
  1173. iop.FirstpartyNetwork = n.FirstpartyNetwork("", firstparty_array)
  1174. iop.Firstparty = n.Introduce_Firstparty(iop.FirstpartyNetwork, entMonitor, probusfors)
  1175. iop.Supplier = n.Introduce_Supplier(supplier_array, entMonitor, probusfors)
  1176. iop.Adiffb = n.Introduce_Supplier(adiffb_array, entMonitor, probusfors)
  1177. iop.Agency = n.Introduce_Agency(agency_array, entMonitor, probusfors)
  1178. iop.Middleman = n.Introduce_Middleman(middleman_project_array, entMonitor, probusfors)
  1179. }
  1180. return iop
  1181. }