network.go 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  1. package service
  2. import (
  3. "context"
  4. "database/sql"
  5. "fmt"
  6. "math"
  7. "sort"
  8. "strings"
  9. "time"
  10. . "app.yhyue.com/moapp/jybase/common"
  11. . "app.yhyue.com/moapp/jybase/date"
  12. "app.yhyue.com/moapp/jybase/encrypt"
  13. . "app.yhyue.com/moapp/jybase/es"
  14. . "app.yhyue.com/moapp/jybase/sort"
  15. . "bp.jydev.jianyu360.cn/CRM/application/api/common"
  16. "bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
  17. "github.com/shopspring/decimal"
  18. "github.com/zeromicro/go-zero/core/logx"
  19. )
  20. var Network = &network{}
  21. type network struct {
  22. }
  23. type networkTree struct {
  24. Count int64 `json:"count"`
  25. Name string `json:"name"`
  26. Children []*networkTreeChild `json:"children"`
  27. }
  28. type networkTreeChild struct {
  29. Count int64 `json:"count"`
  30. Id int64 `json:"id"`
  31. CompanyId string `json:"companyId"`
  32. CompanyName string `json:"companyName"`
  33. Type string `json:"type"`
  34. CreateTime string `json:"createTime"`
  35. }
  36. func (s *networkTree) Len() int {
  37. return len(s.Children)
  38. }
  39. func (s *networkTree) Less(i, j int) bool {
  40. if s.Name == "甲方" {
  41. return s.Children[i].CompanyName < s.Children[j].CompanyName
  42. }
  43. it, err1 := time.ParseInLocation(Date_Full_Layout, s.Children[i].CreateTime, time.Local)
  44. if err1 != nil {
  45. return true
  46. }
  47. jt, err2 := time.ParseInLocation(Date_Full_Layout, s.Children[j].CreateTime, time.Local)
  48. if err2 != nil {
  49. return true
  50. }
  51. return it.Unix() < jt.Unix()
  52. }
  53. func (s *networkTree) Swap(i, j int) {
  54. s.Children[i], s.Children[j] = s.Children[j], s.Children[i]
  55. }
  56. type projectInfo struct {
  57. BuyerCount int64
  58. ProjectCount int64
  59. ProjectAmount float64
  60. MonitorCount int64
  61. ExportId []string
  62. }
  63. type firstpartyNetwork struct {
  64. CompanyId string
  65. CompanyName string
  66. Name string
  67. }
  68. type idName struct {
  69. Id string
  70. Name string
  71. }
  72. type introduceOwnerProject struct {
  73. Networks []*myNetwork
  74. FirstpartyNetwork map[string][]*firstpartyNetwork
  75. Firstparty map[string]*projectInfo
  76. Supplier map[string]*projectInfo
  77. Adiffb map[string]*projectInfo
  78. Agency map[string]*projectInfo
  79. Middleman map[string]*projectInfo
  80. }
  81. type myNetwork struct {
  82. Id int64
  83. Company_id string
  84. Company_name string
  85. Qyxy_id string
  86. Itype int64
  87. Person string
  88. Phone string
  89. Buyer_count int64
  90. Project_count int64
  91. Relate_buyer_id string
  92. Relate_buyer_name 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, pType, pMyType, pMyId := "", "", "", ""
  399. for _, vv := range v.Children {
  400. myId := vv.CompanyId
  401. if vv.Type == "middleman" {
  402. myId = fmt.Sprint(vv.Id)
  403. }
  404. if pMyId != "" {
  405. pMyId += ","
  406. }
  407. pMyId += myId
  408. if pMyType != "" {
  409. pMyType += ","
  410. }
  411. pMyType += vv.Type
  412. myChildIds, myChildTypes := "", ""
  413. if in.Id == "" && v.Name == "甲方" {
  414. for _, vvv := range firstpartyChild[vv.CompanyId] {
  415. if id != "" {
  416. id += ","
  417. }
  418. id += vvv.CompanyId
  419. if pType != "" {
  420. pType += ","
  421. }
  422. pType += vv.Type
  423. if myChildIds != "" {
  424. myChildIds += ","
  425. }
  426. myChildIds += vvv.CompanyId
  427. if myChildTypes != "" {
  428. myChildTypes += ","
  429. }
  430. myChildTypes += vv.Type
  431. }
  432. } else {
  433. if id != "" {
  434. id += ","
  435. }
  436. id += myId
  437. if pType != "" {
  438. pType += ","
  439. }
  440. pType += vv.Type
  441. myChildIds = myId
  442. myChildTypes = vv.Type
  443. }
  444. cm := map[string]interface{}{
  445. "NAME": vv.CompanyName,
  446. "ID": myChildIds,
  447. "SZ_PID0": v.Name,
  448. "SZ_PID1": v.Name + ":" + myId,
  449. "CODE": v.Name + ":" + myId,
  450. "PCODE": v.Name,
  451. "DATACOUNT": vv.Count,
  452. "SZ_LEVEL": 1,
  453. "SZ_LEAF": 1,
  454. "TYPE": myChildTypes,
  455. "MYID": myId,
  456. "MYTYPE": vv.Type,
  457. }
  458. convList = append(convList, cm)
  459. }
  460. pm["ID"] = id
  461. pm["TYPE"] = pType
  462. pm["MYTYPE"] = pMyType
  463. pm["MYID"] = pMyId
  464. convList = append(convList, pm)
  465. }
  466. reply = &types.Reply{
  467. Data: map[string]interface{}{
  468. "count": count,
  469. "list": convList,
  470. },
  471. }
  472. return reply
  473. }
  474. //人脉库-列表
  475. func (n *network) List(in *types.NetWorkListReq) *types.Reply {
  476. if in.Page_size <= 0 {
  477. in.Page_size = 10
  478. }
  479. if in.Current_page <= 0 {
  480. in.Current_page = 1
  481. }
  482. 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
  483. sqlAppendArgs := []interface{}{}
  484. sqlAppend1 := ""
  485. if dbPaging && in.Type != "" {
  486. sqlAppend1 += ` and a.itype=?`
  487. sqlAppendArgs = append(sqlAppendArgs, n.TypeStrConvert(in.Type))
  488. }
  489. comSqlAppend := ""
  490. comSqlArgs := []interface{}{}
  491. if in.Starttime != "" {
  492. comSqlAppend += ` and a.create_time>=?`
  493. comSqlArgs = append(comSqlArgs, in.Starttime+" 00:00:00")
  494. }
  495. if in.Endtime != "" {
  496. comSqlAppend += ` and a.create_time<=?`
  497. if in.Starttime == in.Endtime {
  498. in.Endtime += " 23:59:59"
  499. } else {
  500. in.Endtime += " 00:00:00"
  501. }
  502. comSqlArgs = append(comSqlArgs, in.Endtime)
  503. }
  504. if in.Name != "" {
  505. comSqlAppend += ` and a.company_name like ?`
  506. comSqlArgs = append(comSqlArgs, "%"+in.Name+"%")
  507. }
  508. sqlAppend1 += comSqlAppend
  509. sqlAppendArgs = append(sqlAppendArgs, comSqlArgs...)
  510. var count int64
  511. start := (in.Current_page - 1) * in.Page_size
  512. args := []interface{}{in.PositionId, in.PositionId, in.PositionId}
  513. args = append(args, sqlAppendArgs...)
  514. sqlAppend2 := ""
  515. firstparty_count, supplier_count, adiffb_count, middleman_count, agency_count := 0, 0, 0, 0, 0
  516. if dbPaging {
  517. newArgs := []interface{}{in.PositionId}
  518. newArgs = append(newArgs, sqlAppendArgs...)
  519. count = CrmMysql.CountBySql(`select count(1) as count from crm.connection a where a.position_id=?`+sqlAppend1, newArgs...)
  520. sqlAppend2 = ` limit ?,?`
  521. args = append(args, start, in.Page_size)
  522. itemArgs := []interface{}{in.PositionId}
  523. itemArgs = append(itemArgs, comSqlArgs...)
  524. items := CrmMysql.SelectBySql(`SELECT itype,SUM(1) AS sum FROM crm.connection WHERE position_id=?`+comSqlAppend+` GROUP BY itype`, itemArgs...)
  525. if items != nil {
  526. for _, v := range *items {
  527. switch Int64All(v["itype"]) {
  528. case 1:
  529. firstparty_count = IntAll(v["sum"])
  530. case 2:
  531. supplier_count = IntAll(v["sum"])
  532. case 3:
  533. adiffb_count = IntAll(v["sum"])
  534. case 4:
  535. middleman_count = IntAll(v["sum"])
  536. case 5:
  537. agency_count = IntAll(v["sum"])
  538. }
  539. }
  540. }
  541. }
  542. //
  543. list := []*map[string]interface{}{}
  544. isTjProject := true
  545. probusfors := []string{}
  546. if in.Project_matchme == 1 {
  547. probusfors = NetworkCom.GetMyProbusfor(in.EntAccountId)
  548. if len(probusfors) == 0 {
  549. isTjProject = false
  550. }
  551. }
  552. if isTjProject {
  553. entMonitor := NetworkCom.EntMonitor(in.UserId)
  554. aio := n.AllIntroduceOwner(sqlAppend1, sqlAppend2, args, isTjProject, probusfors, entMonitor)
  555. for _, v := range aio.Networks {
  556. itype := ""
  557. buyer_count, project_count, expect_amount, monitor_count := int64(0), int64(0), float64(0), int64(0)
  558. export_id := []string{}
  559. jump_type, jump_id := "", ""
  560. switch v.Itype {
  561. case 1:
  562. itype = "甲方"
  563. jump_type = "firstparty"
  564. for _, vv := range aio.FirstpartyNetwork[v.Company_id] {
  565. if jump_id != "" {
  566. jump_id += ","
  567. }
  568. jump_id += vv.CompanyId
  569. }
  570. if aio.Firstparty[v.Company_id] != nil {
  571. buyer_count = aio.Firstparty[v.Company_id].BuyerCount
  572. project_count = aio.Firstparty[v.Company_id].ProjectCount
  573. expect_amount = aio.Firstparty[v.Company_id].ProjectAmount
  574. monitor_count = aio.Firstparty[v.Company_id].MonitorCount
  575. export_id = aio.Firstparty[v.Company_id].ExportId
  576. }
  577. case 2:
  578. itype = "供应商"
  579. jump_type = "supplier"
  580. jump_id = v.Company_id
  581. if aio.Supplier[v.Company_id] != nil {
  582. buyer_count = aio.Supplier[v.Company_id].BuyerCount
  583. project_count = aio.Supplier[v.Company_id].ProjectCount
  584. expect_amount = aio.Supplier[v.Company_id].ProjectAmount
  585. monitor_count = aio.Supplier[v.Company_id].MonitorCount
  586. export_id = aio.Supplier[v.Company_id].ExportId
  587. }
  588. case 3:
  589. itype = "同甲异业渠道"
  590. jump_type = "adiffb"
  591. jump_id = v.Company_id
  592. if aio.Adiffb[v.Company_id] != nil {
  593. buyer_count = aio.Adiffb[v.Company_id].BuyerCount
  594. project_count = aio.Adiffb[v.Company_id].ProjectCount
  595. expect_amount = aio.Adiffb[v.Company_id].ProjectAmount
  596. monitor_count = aio.Adiffb[v.Company_id].MonitorCount
  597. export_id = aio.Adiffb[v.Company_id].ExportId
  598. }
  599. case 4:
  600. itype = "中间人"
  601. jump_type = "middleman"
  602. jump_id = fmt.Sprint(v.Id)
  603. buyer_count = v.Buyer_count
  604. if v.Relate_buyer_name != "" {
  605. for _, v := range strings.Split(v.Relate_buyer_name, ",") {
  606. if v == "" {
  607. continue
  608. }
  609. if entMonitor[v] {
  610. monitor_count++
  611. }
  612. }
  613. }
  614. if v.Relate_project_id != "" {
  615. export_id = strings.Split(v.Relate_project_id, ",")
  616. for _, v := range export_id {
  617. if aio.Middleman[v] != nil {
  618. project_count++
  619. expect_amount += aio.Middleman[v].ProjectAmount
  620. }
  621. }
  622. }
  623. case 5:
  624. itype = "招标代理机构"
  625. jump_type = "agency"
  626. jump_id = v.Company_id
  627. if aio.Agency[v.Company_id] != nil {
  628. buyer_count = aio.Agency[v.Company_id].BuyerCount
  629. project_count = aio.Agency[v.Company_id].ProjectCount
  630. expect_amount = aio.Agency[v.Company_id].ProjectAmount
  631. monitor_count = aio.Agency[v.Company_id].MonitorCount
  632. export_id = aio.Agency[v.Company_id].ExportId
  633. }
  634. }
  635. if buyer_count < in.Buyercount_start {
  636. continue
  637. } else if in.Buyercount_end > 0 && buyer_count > in.Buyercount_end {
  638. continue
  639. } else if in.Monitor == 1 && monitor_count <= 0 {
  640. continue
  641. } else if in.Monitor == -1 && monitor_count > 0 {
  642. continue
  643. } else if monitor_count < in.Monitorcount_start {
  644. continue
  645. } else if in.Monitorcount_end > 0 && monitor_count > in.Monitorcount_end {
  646. continue
  647. } else if in.Project_matchme == 1 && project_count == 0 {
  648. continue
  649. }
  650. if !dbPaging {
  651. switch v.Itype {
  652. case 1:
  653. firstparty_count++
  654. case 2:
  655. supplier_count++
  656. case 3:
  657. adiffb_count++
  658. case 4:
  659. middleman_count++
  660. case 5:
  661. agency_count++
  662. }
  663. if in.Type != "" && n.TypeStrConvert(in.Type) != v.Itype {
  664. continue
  665. }
  666. }
  667. export_url := ""
  668. if len(export_id) > 0 {
  669. exportIdRepeat := map[string]bool{}
  670. exportId := ""
  671. for _, v := range export_id {
  672. if exportIdRepeat[v] {
  673. continue
  674. }
  675. exportIdRepeat[v] = true
  676. if exportId != "" {
  677. exportId += ","
  678. }
  679. exportId += v
  680. }
  681. export_url = "/subscribepay/network/projectExport?export_id=" + encrypt.SE.EncodeStringByCheck(exportId)
  682. }
  683. url := ""
  684. if v.Qyxy_id != "" && (jump_type == "supplier" || jump_type == "adiffb") {
  685. url = "/swordfish/page_big_pc/ent_portrait/" + encrypt.EncodeArticleId2ByCheck(v.Qyxy_id)
  686. } else if jump_type == "firstparty" && v.Company_name != "" {
  687. url = "/swordfish/page_big_pc/unit_portrayal/" + v.Company_name
  688. }
  689. list = append(list, &map[string]interface{}{
  690. "company_id": v.Company_id,
  691. "company_name": v.Company_name,
  692. "type": itype,
  693. "jump_type": jump_type,
  694. "jump_id": jump_id,
  695. "person": v.Person,
  696. "phone": v.Phone,
  697. "buyer_count": buyer_count,
  698. "monitor_count": monitor_count,
  699. "expect_amount": RetainDecimal(expect_amount/10000, 2),
  700. "project_count": project_count,
  701. "create_time": v.Create_time,
  702. "export_url": export_url,
  703. "url": url,
  704. "id": v.Id,
  705. })
  706. }
  707. }
  708. csList := &ComSortList{
  709. SortKeys: []*ComSortKey{
  710. &ComSortKey{
  711. Keys: []string{"expect_amount"},
  712. Order: 1,
  713. Type: "float",
  714. },
  715. },
  716. List: list,
  717. }
  718. if in.Order_amount == -1 {
  719. csList.SortKeys[0].Order = -1
  720. }
  721. if in.Order_amount != 0 {
  722. sort.Sort(csList)
  723. }
  724. finalList := []*map[string]interface{}{}
  725. if !dbPaging {
  726. count = int64(len(csList.List))
  727. if count > 0 && start < count {
  728. end := start + in.Page_size
  729. if end > count {
  730. end = count
  731. }
  732. finalList = csList.List[start:end]
  733. }
  734. } else {
  735. finalList = csList.List
  736. }
  737. total_page := int64(math.Ceil(float64(count) / float64(in.Page_size)))
  738. return &types.Reply{
  739. Data: map[string]interface{}{
  740. "count": count,
  741. "total_page": total_page,
  742. "firstparty_count": firstparty_count,
  743. "supplier_count": supplier_count,
  744. "adiffb_count": adiffb_count,
  745. "middleman_count": middleman_count,
  746. "agency_count": agency_count,
  747. "list": finalList,
  748. },
  749. }
  750. }
  751. //
  752. func (n *network) FirstpartyNetwork(name string, values []string) map[string][]*firstpartyNetwork {
  753. result := map[string][]*firstpartyNetwork{}
  754. wh, args := NetworkCom.WhArgs(values)
  755. 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
  756. inner join information.ent_code b on (a.a_id in (` + wh + `) and b.pcode in ('0100','0200') and a.code=b.code)`
  757. if name != "" {
  758. q += ` where c.company_name like ?`
  759. args = append(args, "%"+name+"%")
  760. }
  761. q += ` order by b.name,a.a_id,a.b_name`
  762. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  763. if err != nil {
  764. logx.Error(err)
  765. return result
  766. }
  767. for rows.Next() {
  768. var (
  769. a_id string
  770. company_id string
  771. company_name string
  772. name string
  773. )
  774. if err := rows.Scan(&a_id, &company_id, &company_name, &name); err != nil {
  775. logx.Error(err)
  776. continue
  777. }
  778. if company_id == "" || company_name == "" {
  779. continue
  780. }
  781. result[a_id] = append(result[a_id], &firstpartyNetwork{
  782. CompanyId: company_id,
  783. CompanyName: company_name,
  784. Name: name,
  785. })
  786. }
  787. return result
  788. }
  789. //
  790. func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
  791. values := []string{}
  792. vm := map[string]*projectInfo{}
  793. for _, v := range fpn {
  794. for _, vv := range v {
  795. vm[vv.CompanyId] = &projectInfo{}
  796. values = append(values, vv.CompanyId)
  797. }
  798. }
  799. result := map[string]*projectInfo{}
  800. if len(values) == 0 {
  801. return result
  802. }
  803. wh, args := NetworkCom.WhArgs(values)
  804. 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 + `)`
  805. if len(probusfors) > 0 {
  806. newWh, newArgs := NetworkCom.WhArgs(probusfors)
  807. q += ` and hasAny(property_form,[` + newWh + `])`
  808. args = append(args, newArgs...)
  809. }
  810. q += ` group by buyer_id`
  811. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  812. if err != nil {
  813. logx.Error(err)
  814. return nil
  815. }
  816. for rows.Next() {
  817. var (
  818. buyer_id string
  819. project_count uint64
  820. project_amount decimal.Decimal
  821. project_id []string
  822. )
  823. if err := rows.Scan(&buyer_id, &project_count, &project_amount, &project_id); err != nil {
  824. logx.Error(err)
  825. continue
  826. }
  827. if vm[buyer_id] == nil {
  828. continue
  829. }
  830. vm[buyer_id].ProjectCount += int64(project_count)
  831. pf, _ := project_amount.Float64()
  832. vm[buyer_id].ProjectAmount += pf
  833. vm[buyer_id].ExportId = project_id
  834. }
  835. rows.Close()
  836. if err := rows.Err(); err != nil {
  837. logx.Error(err)
  838. }
  839. for k, v := range fpn {
  840. if result[k] == nil {
  841. result[k] = &projectInfo{}
  842. }
  843. result[k].BuyerCount = int64(len(v))
  844. for _, vv := range v {
  845. if entMonitor[vv.CompanyName] {
  846. result[k].MonitorCount++
  847. }
  848. if vm[vv.CompanyId] == nil {
  849. continue
  850. }
  851. result[k].ProjectCount += vm[vv.CompanyId].ProjectCount
  852. result[k].ProjectAmount += vm[vv.CompanyId].ProjectAmount
  853. result[k].ExportId = append(result[k].ExportId, vm[vv.CompanyId].ExportId...)
  854. }
  855. }
  856. return result
  857. }
  858. //
  859. func (n *network) Introduce_Supplier(values []string, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
  860. if len(values) == 0 {
  861. return map[string]*projectInfo{}
  862. }
  863. wh, args := NetworkCom.WhArgs(values)
  864. vbs := map[string][]*idName{}
  865. repeat := map[string]bool{}
  866. whRepeat := map[string]map[string]bool{}
  867. buyers := []string{}
  868. q := `select winner_id,buyer_id,buyer from information.transaction_info where hasAny(winner_id,[` + wh + `])`
  869. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  870. if err != nil {
  871. logx.Error(err)
  872. } else {
  873. for rows.Next() {
  874. var (
  875. winner_id []string
  876. buyer_id string
  877. buyer string
  878. )
  879. if err := rows.Scan(&winner_id, &buyer_id, &buyer); err != nil {
  880. logx.Error(err)
  881. continue
  882. }
  883. if buyer_id == "" || buyer == "" {
  884. continue
  885. }
  886. if !repeat[buyer_id] {
  887. repeat[buyer_id] = true
  888. buyers = append(buyers, buyer_id)
  889. }
  890. for _, v := range winner_id {
  891. if whRepeat[v] != nil && whRepeat[v][buyer_id] {
  892. continue
  893. }
  894. if whRepeat[v] == nil {
  895. whRepeat[v] = map[string]bool{}
  896. }
  897. whRepeat[v][buyer_id] = true
  898. vbs[v] = append(vbs[v], &idName{
  899. Id: buyer_id,
  900. Name: buyer,
  901. })
  902. }
  903. }
  904. rows.Close()
  905. if err := rows.Err(); err != nil {
  906. logx.Error(err)
  907. }
  908. }
  909. return n.MakeProjectInfo(buyers, vbs, probusfors, entMonitor)
  910. }
  911. //
  912. func (n *network) Introduce_Agency(values []string, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
  913. if len(values) == 0 {
  914. return map[string]*projectInfo{}
  915. }
  916. wh, args := NetworkCom.WhArgs(values)
  917. q := `select DISTINCT agency_id,buyer_id,buyer from information.transaction_info where agency_id in (` + wh + `)`
  918. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  919. if err != nil {
  920. logx.Error(err)
  921. return nil
  922. }
  923. vbs := map[string][]*idName{}
  924. buyers := []string{}
  925. repeat := map[string]bool{}
  926. for rows.Next() {
  927. var (
  928. agency_id string
  929. buyer_id string
  930. buyer string
  931. )
  932. if err := rows.Scan(&agency_id, &buyer_id, &buyer); err != nil {
  933. logx.Error(err)
  934. continue
  935. }
  936. if buyer_id == "" || buyer == "" {
  937. continue
  938. }
  939. vbs[agency_id] = append(vbs[agency_id], &idName{
  940. Id: buyer_id,
  941. Name: buyer,
  942. })
  943. if !repeat[buyer_id] {
  944. repeat[buyer_id] = true
  945. buyers = append(buyers, buyer_id)
  946. }
  947. }
  948. rows.Close()
  949. if err := rows.Err(); err != nil {
  950. logx.Error(err)
  951. }
  952. return n.MakeProjectInfo(buyers, vbs, probusfors, entMonitor)
  953. }
  954. //
  955. func (n *network) Introduce_Middleman(values []string, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
  956. result := map[string]*projectInfo{}
  957. if len(values) == 0 {
  958. return result
  959. }
  960. wh, args := NetworkCom.WhArgs(values)
  961. q := `select DISTINCT project_id,project_money from information.transaction_info where project_id in (` + wh + `)`
  962. if len(probusfors) > 0 {
  963. newWh, newArgs := NetworkCom.WhArgs(probusfors)
  964. q += ` and hasAny(property_form,[` + newWh + `])`
  965. args = append(args, newArgs...)
  966. }
  967. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  968. if err != nil {
  969. logx.Error(err)
  970. return nil
  971. }
  972. for rows.Next() {
  973. var (
  974. project_id string
  975. project_money decimal.Decimal
  976. )
  977. if err := rows.Scan(&project_id, &project_money); err != nil {
  978. logx.Error(err)
  979. continue
  980. }
  981. pf, _ := project_money.Float64()
  982. result[project_id] = &projectInfo{
  983. ProjectAmount: pf,
  984. }
  985. }
  986. rows.Close()
  987. if err := rows.Err(); err != nil {
  988. logx.Error(err)
  989. }
  990. return result
  991. }
  992. //
  993. func (n *network) TypeStrConvert(itype string) int64 {
  994. //firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构
  995. switch itype {
  996. case "firstparty":
  997. return 1
  998. case "supplier":
  999. return 2
  1000. case "adiffb":
  1001. return 3
  1002. case "middleman":
  1003. return 4
  1004. case "agency":
  1005. return 5
  1006. }
  1007. return 0
  1008. }
  1009. //
  1010. func (n *network) TypeIntConvert(itype int64) string {
  1011. //firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构
  1012. switch itype {
  1013. case 1:
  1014. return "firstparty"
  1015. case 2:
  1016. return "supplier"
  1017. case 3:
  1018. return "adiffb"
  1019. case 4:
  1020. return "middleman"
  1021. case 5:
  1022. return "agency"
  1023. }
  1024. return ""
  1025. }
  1026. //
  1027. func (n *network) GetQyxyId(ids []string) map[string]string {
  1028. wh, args := NetworkCom.WhArgs(ids)
  1029. q := `select id,company_id from information.ent_info where id in (` + wh + `)`
  1030. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  1031. m := map[string]string{}
  1032. if err != nil {
  1033. logx.Error(err)
  1034. } else {
  1035. for rows.Next() {
  1036. var (
  1037. id string
  1038. company_id string
  1039. )
  1040. if err := rows.Scan(&id, &company_id); err != nil {
  1041. logx.Error(err)
  1042. continue
  1043. }
  1044. m[id] = company_id
  1045. }
  1046. rows.Close()
  1047. if err := rows.Err(); err != nil {
  1048. logx.Error(err)
  1049. }
  1050. }
  1051. return m
  1052. }
  1053. //
  1054. func (n *network) BuyerProjectInfo(ids []string, probusfors []string) map[string]*projectInfo {
  1055. vm := map[string]*projectInfo{}
  1056. wh, args := NetworkCom.WhArgs(ids)
  1057. 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 + `)`
  1058. if len(probusfors) > 0 {
  1059. newWh, newArgs := NetworkCom.WhArgs(probusfors)
  1060. q += ` and hasAny(property_form,[` + newWh + `])`
  1061. args = append(args, newArgs...)
  1062. }
  1063. q += ` group by buyer_id`
  1064. rows, err := ClickhouseConn.Query(context.Background(), q, args...)
  1065. if err != nil {
  1066. logx.Error(err)
  1067. return nil
  1068. }
  1069. for rows.Next() {
  1070. var (
  1071. buyer_id string
  1072. project_count uint64
  1073. project_amount decimal.Decimal
  1074. project_id []string
  1075. )
  1076. if err := rows.Scan(&buyer_id, &project_count, &project_amount, &project_id); err != nil {
  1077. logx.Error(err)
  1078. continue
  1079. }
  1080. pf, _ := project_amount.Float64()
  1081. vm[buyer_id] = &projectInfo{
  1082. ProjectCount: int64(project_count),
  1083. ExportId: project_id,
  1084. ProjectAmount: pf,
  1085. }
  1086. }
  1087. rows.Close()
  1088. if err := rows.Err(); err != nil {
  1089. logx.Error(err)
  1090. }
  1091. return vm
  1092. }
  1093. //
  1094. func (n *network) MakeProjectInfo(buyers []string, vbs map[string][]*idName, probusfors []string, entMonitor map[string]bool) map[string]*projectInfo {
  1095. pis := n.BuyerProjectInfo(buyers, probusfors)
  1096. vm := map[string]*projectInfo{}
  1097. for k, v := range vbs {
  1098. pi := &projectInfo{
  1099. BuyerCount: int64(len(v)),
  1100. }
  1101. re := map[string]bool{}
  1102. for _, vv := range v {
  1103. if pis[vv.Id] != nil {
  1104. pi.ProjectCount += pis[vv.Id].ProjectCount
  1105. pi.ProjectAmount += pis[vv.Id].ProjectAmount
  1106. for _, vvv := range pis[vv.Id].ExportId {
  1107. if re[vvv] {
  1108. continue
  1109. }
  1110. pi.ExportId = append(pi.ExportId, vvv)
  1111. re[vvv] = true
  1112. }
  1113. }
  1114. if entMonitor[vv.Name] {
  1115. pi.MonitorCount++
  1116. }
  1117. }
  1118. vm[k] = pi
  1119. }
  1120. return vm
  1121. }
  1122. //
  1123. func (n *network) AllIntroduceOwner(sqlAppend1, sqlAppend2 string, args []interface{}, isTjProject bool, probusfors []string, entMonitor map[string]bool) *introduceOwnerProject {
  1124. 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
  1125. 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
  1126. listTemp := CrmMysql.SelectBySql(q, args...)
  1127. firstparty_array, supplier_array, adiffb_array, agency_array, middleman_project_array := []string{}, []string{}, []string{}, []string{}, []string{}
  1128. myNetworks := []*myNetwork{}
  1129. for _, v := range *listTemp {
  1130. myNetwork := &myNetwork{
  1131. Id: Int64All(v["id"]),
  1132. Company_id: ObjToString(v["company_id"]),
  1133. Company_name: ObjToString(v["company_name"]),
  1134. Qyxy_id: ObjToString(v["qyxy_id"]),
  1135. Itype: Int64All(v["itype"]),
  1136. Person: ObjToString(v["person"]),
  1137. Phone: ObjToString(v["phone"]),
  1138. Buyer_count: Int64All(v["buyer_count"]),
  1139. Project_count: Int64All(v["project_count"]),
  1140. Relate_buyer_id: ObjToString(v["relate_buyer_id"]),
  1141. Relate_buyer_name: ObjToString(v["relate_buyer_name"]),
  1142. Relate_project_id: ObjToString(v["relate_project_id"]),
  1143. Create_time: ObjToString(v["create_time"]),
  1144. }
  1145. switch myNetwork.Itype {
  1146. case 1:
  1147. firstparty_array = append(firstparty_array, myNetwork.Company_id)
  1148. case 2:
  1149. supplier_array = append(supplier_array, myNetwork.Company_id)
  1150. case 3:
  1151. adiffb_array = append(adiffb_array, myNetwork.Company_id)
  1152. case 4:
  1153. if myNetwork.Relate_project_id != "" {
  1154. middleman_project_array = append(middleman_project_array, strings.Split(myNetwork.Relate_project_id, ",")...)
  1155. }
  1156. case 5:
  1157. agency_array = append(agency_array, myNetwork.Company_id)
  1158. }
  1159. myNetworks = append(myNetworks, myNetwork)
  1160. }
  1161. iop := &introduceOwnerProject{
  1162. Networks: myNetworks,
  1163. FirstpartyNetwork: map[string][]*firstpartyNetwork{},
  1164. Firstparty: map[string]*projectInfo{},
  1165. Supplier: map[string]*projectInfo{},
  1166. Adiffb: map[string]*projectInfo{},
  1167. Agency: map[string]*projectInfo{},
  1168. Middleman: map[string]*projectInfo{},
  1169. }
  1170. if isTjProject {
  1171. iop.FirstpartyNetwork = n.FirstpartyNetwork("", firstparty_array)
  1172. iop.Firstparty = n.Introduce_Firstparty(iop.FirstpartyNetwork, entMonitor, probusfors)
  1173. iop.Supplier = n.Introduce_Supplier(supplier_array, entMonitor, probusfors)
  1174. iop.Adiffb = n.Introduce_Supplier(adiffb_array, entMonitor, probusfors)
  1175. iop.Agency = n.Introduce_Agency(agency_array, entMonitor, probusfors)
  1176. iop.Middleman = n.Introduce_Middleman(middleman_project_array, entMonitor, probusfors)
  1177. }
  1178. return iop
  1179. }