|
@@ -31,11 +31,12 @@ type networkTree struct {
|
|
|
Children []*networkTreeChild `json:"children"`
|
|
|
}
|
|
|
type networkTreeChild struct {
|
|
|
- Count int64 `json:"count"`
|
|
|
- Name string `json:"name"`
|
|
|
- Id string `json:"id"`
|
|
|
- Type string `json:"type"`
|
|
|
- CreateTime string `json:"createTime"`
|
|
|
+ Count int64 `json:"count"`
|
|
|
+ Id int64 `json:"id"`
|
|
|
+ CompanyId string `json:"companyId"`
|
|
|
+ CompanyName string `json:"companyName"`
|
|
|
+ Type string `json:"type"`
|
|
|
+ CreateTime string `json:"createTime"`
|
|
|
}
|
|
|
|
|
|
func (s *networkTree) Len() int {
|
|
@@ -44,7 +45,7 @@ func (s *networkTree) Len() int {
|
|
|
|
|
|
func (s *networkTree) Less(i, j int) bool {
|
|
|
if s.Name == "甲方" {
|
|
|
- return s.Children[i].Name < s.Children[j].Name
|
|
|
+ return s.Children[i].CompanyName < s.Children[j].CompanyName
|
|
|
}
|
|
|
it, err1 := time.ParseInLocation(Date_Full_Layout, s.Children[i].CreateTime, time.Local)
|
|
|
if err1 != nil {
|
|
@@ -91,12 +92,13 @@ func (n *network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
|
|
|
}
|
|
|
values := []interface{}{}
|
|
|
ioi := strings.Split(in.Introduce_owner_id, ",")
|
|
|
+ ioqi := strings.Split(in.Introduce_owner_qyxy_id, ",")
|
|
|
ion := strings.Split(in.Introduce_owner_name, ",")
|
|
|
- if len(ioi) != len(ion) {
|
|
|
+ if len(ioi) != len(ion) || len(ioi) != len(ioqi) {
|
|
|
return false
|
|
|
}
|
|
|
for k, v := range ioi {
|
|
|
- values = append(values, in.PositionId, in.EntId, in.EntDeptId, in.EntUserId, cid, v, ion[k], 1, nowFormat)
|
|
|
+ values = append(values, in.PositionId, in.EntId, in.EntDeptId, in.EntUserId, cid, ioqi[k], v, ion[k], 1, nowFormat)
|
|
|
}
|
|
|
ipi := strings.Split(in.Introduce_project_id, ",")
|
|
|
ipn := strings.Split(in.Introduce_project_name, ",")
|
|
@@ -104,13 +106,13 @@ func (n *network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
|
|
|
return false
|
|
|
}
|
|
|
for k, v := range ipi {
|
|
|
- values = append(values, in.PositionId, in.EntId, in.EntDeptId, in.EntUserId, cid, v, ipn[k], 2, nowFormat)
|
|
|
+ values = append(values, in.PositionId, in.EntId, in.EntDeptId, in.EntUserId, cid, nil, v, ipn[k], 2, nowFormat)
|
|
|
}
|
|
|
var r2 int64
|
|
|
if isUpdate {
|
|
|
r2 = CrmMysql.UpdateOrDeleteBySqlByTx(tx, `delete from crm.connection_introduce where connection_id=? and position_id=?`, in.Id, in.PositionId)
|
|
|
}
|
|
|
- r3, _ := CrmMysql.InsertBatchByTx(tx, "crm.connection_introduce", []string{"position_id", "ent_id", "ent_dept_id", "ent_user_id", "connection_id", "relate_id", "relate_name", "itype", "create_time"}, values)
|
|
|
+ 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)
|
|
|
return r2 >= 0 && r3 > 0
|
|
|
}
|
|
|
itype := n.TypeStrConvert(in.Type)
|
|
@@ -148,7 +150,7 @@ func (n *network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
|
|
|
}
|
|
|
var r1 int64
|
|
|
if CrmMysql.ExecTx("新增人脉", func(tx *sql.Tx) bool {
|
|
|
- _, r1 = CrmMysql.InsertBatchByTx(tx, "crm.connection", []string{"position_id", "ent_id", "ent_dept_id", "ent_user_id", "itype", "company_name", "company_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.Contact_person, in.Contact_phone, 1, nowFormat, nowFormat})
|
|
|
+ _, 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})
|
|
|
return r1 > 0 && saveIntroduce(tx, r1, false)
|
|
|
}) {
|
|
|
reply.Data = map[string]interface{}{
|
|
@@ -163,7 +165,7 @@ func (n *network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
|
|
|
//人脉库-业主名称联想
|
|
|
func (n *network) Associate(in *types.AssociateReq) (reply *types.Reply) {
|
|
|
//类型;firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 middleman_owner:中间人-业主 middleman_project:中间人-项目 agency:招标代理机构
|
|
|
- res := []map[string]interface{}{}
|
|
|
+ res := []map[string]string{}
|
|
|
reply = &types.Reply{Data: res}
|
|
|
in.Name = strings.TrimSpace(in.Name)
|
|
|
if in.Name == "" {
|
|
@@ -182,6 +184,7 @@ func (n *network) Associate(in *types.AssociateReq) (reply *types.Reply) {
|
|
|
logx.Error(err)
|
|
|
} else {
|
|
|
repeat := map[string]bool{}
|
|
|
+ ids := []string{}
|
|
|
for rows.Next() {
|
|
|
var (
|
|
|
winner_id []string
|
|
@@ -199,18 +202,23 @@ func (n *network) Associate(in *types.AssociateReq) (reply *types.Reply) {
|
|
|
if k >= len(winner_id) {
|
|
|
continue
|
|
|
}
|
|
|
- res = append(res, map[string]interface{}{
|
|
|
+ ids = append(ids, winner_id[k])
|
|
|
+ res = append(res, map[string]string{
|
|
|
"company_name": v,
|
|
|
"company_id": winner_id[k],
|
|
|
})
|
|
|
+ if len(res) == pageSize {
|
|
|
+ break
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
rows.Close()
|
|
|
if err := rows.Err(); err != nil {
|
|
|
logx.Error(err)
|
|
|
}
|
|
|
- if len(res) > pageSize {
|
|
|
- res = res[:pageSize]
|
|
|
+ qyxyId := n.GetQyxyId(ids)
|
|
|
+ for _, v := range res {
|
|
|
+ v["qyxy_id"] = qyxyId[v["company_id"]]
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -228,14 +236,15 @@ func (n *network) Associate(in *types.AssociateReq) (reply *types.Reply) {
|
|
|
case "agency":
|
|
|
must = append(must, `{"term":{"company_unit_type":4}}`)
|
|
|
}
|
|
|
- q := fmt.Sprintf(`{"query":{"bool":{"must":[%s]}},"size":%d,"_source":["id","company_name"]}`, strings.Join(must, ","), pageSize)
|
|
|
+ q := fmt.Sprintf(`{"query":{"bool":{"must":[%s]}},"size":%d,"_source":["id","company_id","company_name"]}`, strings.Join(must, ","), pageSize)
|
|
|
logx.Info("人脉库-业主名称联想", q)
|
|
|
datas := VarEs.Get("ent_info", "ent_info", q)
|
|
|
if datas != nil {
|
|
|
for _, v := range *datas {
|
|
|
- res = append(res, map[string]interface{}{
|
|
|
+ res = append(res, map[string]string{
|
|
|
"company_name": ObjToString(v["company_name"]),
|
|
|
"company_id": ObjToString(v["id"]),
|
|
|
+ "qyxy_id": ObjToString(v["company_id"]),
|
|
|
})
|
|
|
}
|
|
|
}
|
|
@@ -254,7 +263,7 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
|
|
|
var count int64
|
|
|
var list []*networkTree
|
|
|
if in.Id != "" {
|
|
|
- if in.Type == 1 {
|
|
|
+ if in.Type == "firstparty" {
|
|
|
result := n.FirstpartyNetwork(in.Name, []string{in.Id})
|
|
|
if result[in.Id] != nil {
|
|
|
nameIndex := map[string]int{}
|
|
@@ -273,12 +282,12 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
|
|
|
wait.Done()
|
|
|
}()
|
|
|
ntc := &networkTreeChild{
|
|
|
- Name: cName,
|
|
|
- Id: cId,
|
|
|
- Type: "firstparty",
|
|
|
+ CompanyName: cName,
|
|
|
+ CompanyId: cId,
|
|
|
+ Type: "firstparty",
|
|
|
}
|
|
|
if wh != "" {
|
|
|
- thisArgs := []interface{}{ntc.Id}
|
|
|
+ thisArgs := []interface{}{ntc.CompanyId}
|
|
|
thisArgs = append(thisArgs, newArgs...)
|
|
|
ntc.Count = NetworkCom.Count(`select count(1) from information.transaction_info where buyer_id=? and hasAny(property_form,[`+wh+`])`, thisArgs...)
|
|
|
}
|
|
@@ -293,7 +302,7 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- q := `SELECT a.company_id,a.company_name,a.itype,a.create_time,COUNT(b.id) AS ipc FROM crm.connection a
|
|
|
+ q := `SELECT a.id,a.company_id,a.company_name,a.itype,a.create_time,COUNT(b.id) AS ipc FROM crm.connection a
|
|
|
LEFT JOIN crm.connection_introduce b ON (b.position_id=? AND b.itype=2 AND a.id=b.connection_id) WHERE a.position_id=?`
|
|
|
args := []interface{}{in.PositionId, in.PositionId}
|
|
|
if in.Name != "" {
|
|
@@ -342,13 +351,14 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
|
|
|
company_name = "未填写"
|
|
|
}
|
|
|
ntc := &networkTreeChild{
|
|
|
- Name: company_name,
|
|
|
- Id: ObjToString(v["company_id"]),
|
|
|
- Type: n.TypeIntConvert(Int64All(v["itype"])),
|
|
|
- CreateTime: ObjToString(v["create_time"]),
|
|
|
+ Id: Int64All(v["id"]),
|
|
|
+ CompanyName: company_name,
|
|
|
+ CompanyId: ObjToString(v["company_id"]),
|
|
|
+ Type: n.TypeIntConvert(Int64All(v["itype"])),
|
|
|
+ CreateTime: ObjToString(v["create_time"]),
|
|
|
}
|
|
|
if wh != "" {
|
|
|
- thisArgs := []interface{}{ntc.Id}
|
|
|
+ thisArgs := []interface{}{ntc.CompanyId}
|
|
|
thisArgs = append(thisArgs, newArgs...)
|
|
|
if itype == 1 {
|
|
|
ntc.Count = NetworkCom.Count(`select count(1) from information.transaction_info where buyer_id=? and hasAny(property_form,[`+wh+`])`, thisArgs...)
|
|
@@ -393,14 +403,18 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
|
|
|
if pType != "" {
|
|
|
pType += ","
|
|
|
}
|
|
|
- ID += vv.Id
|
|
|
+ tempId := vv.CompanyId
|
|
|
+ if vv.Type == "middleman" {
|
|
|
+ tempId = fmt.Sprint(vv.Id)
|
|
|
+ }
|
|
|
+ ID += tempId
|
|
|
pType += vv.Type
|
|
|
cm := map[string]interface{}{
|
|
|
- "NAME": vv.Name,
|
|
|
- "ID": vv.Id,
|
|
|
+ "NAME": vv.CompanyName,
|
|
|
+ "ID": tempId,
|
|
|
"SZ_PID0": v.Name,
|
|
|
- "SZ_PID1": v.Name + ":" + vv.Id,
|
|
|
- "CODE": v.Name + ":" + vv.Id,
|
|
|
+ "SZ_PID1": v.Name + ":" + tempId,
|
|
|
+ "CODE": v.Name + ":" + tempId,
|
|
|
"PCODE": v.Name,
|
|
|
"DATACOUNT": vv.Count,
|
|
|
"SZ_LEVEL": 1,
|
|
@@ -424,7 +438,7 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
|
|
|
|
|
|
//人脉库-列表
|
|
|
func (n *network) List(in *types.NetWorkListReq) *types.Reply {
|
|
|
- q := `select a.company_id,a.company_name,a.itype,a.contact_person as person,a.contact_phone as phone,count(DISTINCT if(b.itype=1,b.relate_id,null)) as buyer_count,count(DISTINCT if(b.itype=2,b.relate_id,null)) as project_count,GROUP_CONCAT(IF(b.itype=1,b.relate_id,NULL)) AS relate_buyer_id,GROUP_CONCAT(IF(b.itype=2,b.relate_id,NULL)) AS relate_project_id,a.create_time from crm.connection a
|
|
|
+ q := `select a.id,a.company_id,a.company_name,a.qyxy_id,a.itype,a.contact_person as person,a.contact_phone as phone,count(DISTINCT if(b.itype=1,b.relate_id,null)) as buyer_count,count(DISTINCT if(b.itype=2,b.relate_id,null)) as project_count,GROUP_CONCAT(IF(b.itype=1,b.relate_id,NULL)) AS relate_buyer_id,GROUP_CONCAT(IF(b.itype=2,b.relate_id,NULL)) AS relate_project_id,a.create_time from crm.connection a
|
|
|
left join crm.connection_introduce b on (a.id=b.connection_id) where a.position_id=?`
|
|
|
args := []interface{}{in.PositionId}
|
|
|
if in.Type != "" {
|
|
@@ -537,7 +551,7 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
|
|
|
case 4:
|
|
|
itype = "中间人"
|
|
|
jump_type = "middleman"
|
|
|
- jump_id = company_id
|
|
|
+ jump_id = fmt.Sprint(Int64All(v["id"]))
|
|
|
middleman_count++
|
|
|
buyer_count = Int64All(v["buyer_count"])
|
|
|
project_count = Int64All(v["project_count"])
|
|
@@ -587,16 +601,19 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
|
|
|
} else if in.Project_matchme == 1 && project_count == 0 {
|
|
|
continue
|
|
|
}
|
|
|
-
|
|
|
export_url := ""
|
|
|
if len(export_id) > 0 {
|
|
|
export_url = "/subscribepay/network/projectExport?export_id=" + encrypt.SE.EncodeStringByCheck(strings.Join(export_id, ","))
|
|
|
}
|
|
|
+ url := ""
|
|
|
company_name, _ := v["company_name"].(string)
|
|
|
- url := "/swordfish/page_big_pc/unit_portrayal/" + company_name
|
|
|
if company_name == "" {
|
|
|
company_name = "未填写"
|
|
|
- url = ""
|
|
|
+ }
|
|
|
+ if qyxy_id := ObjToString(v["qyxy_id"]); qyxy_id != "" && (jump_type == "supplier" || jump_type == "adiffb") {
|
|
|
+ url = "/swordfish/page_big_pc/ent_portrait/" + encrypt.EncodeArticleId2ByCheck(qyxy_id)
|
|
|
+ } else if jump_type == "firstparty" && company_name != "" {
|
|
|
+ url = "/swordfish/page_big_pc/unit_portrayal/" + company_name
|
|
|
}
|
|
|
list = append(list, &map[string]interface{}{
|
|
|
"company_id": company_id,
|
|
@@ -943,3 +960,31 @@ func (n *network) TypeIntConvert(itype int64) string {
|
|
|
}
|
|
|
return ""
|
|
|
}
|
|
|
+
|
|
|
+//
|
|
|
+func (n *network) GetQyxyId(ids []string) map[string]string {
|
|
|
+ wh, args := NetworkCom.WhArgs(ids)
|
|
|
+ q := `select id,company_id from information.ent_info where id in (` + wh + `)`
|
|
|
+ rows, err := ClickhouseConn.Query(context.Background(), q, args...)
|
|
|
+ m := map[string]string{}
|
|
|
+ if err != nil {
|
|
|
+ logx.Error(err)
|
|
|
+ } else {
|
|
|
+ for rows.Next() {
|
|
|
+ var (
|
|
|
+ id string
|
|
|
+ company_id string
|
|
|
+ )
|
|
|
+ if err := rows.Scan(&id, &company_id); err != nil {
|
|
|
+ logx.Error(err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ m[id] = company_id
|
|
|
+ }
|
|
|
+ rows.Close()
|
|
|
+ if err := rows.Err(); err != nil {
|
|
|
+ logx.Error(err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return m
|
|
|
+}
|