浏览代码

feat:人脉保存

wangchuanjin 1 年之前
父节点
当前提交
e57b8fa82b

+ 5 - 1
api/application.api

@@ -188,6 +188,10 @@ type (
 		Key            string `json:"key"`                     //创建线索:more_create_clue 创建机会:more_create_chance 创建客户:more_create_custom
 	}
 	ProjectListReq {
+		PositionId   int64  `header:"positionId,optional"`
+		EntId        string `header:"entId,optional"`
+		EntUserId    string `header:"entUserId,optional"`
+		DeptId       string `header:"deptId,optional"` //部门id
 		PageNum      int64  `json:"pageNum"`
 		PageSize     int64  `json:"pageSize"`
 		BusinessType string `json:"businessType"`
@@ -221,7 +225,7 @@ type (
 		Introduce_owner_name   string `json:"introduce_owner_name,optional"`
 		Introduce_project_id   string `json:"introduce_project_id,optional"`
 		Introduce_project_name string `json:"introduce_project_name,optional"`
-		Id                     string `json:"id,optional"`
+		Id                     int64  `json:"id,optional"`
 		Type                   string `json:"type,optional"`
 	}
 	AssociateReq {

+ 3 - 2
api/common/initconfig.go

@@ -1,13 +1,14 @@
 package common
 
 import (
-	"app.yhyue.com/moapp/jypkg/middleground"
 	"context"
 	"flag"
 	"fmt"
 	"log"
 	"time"
 
+	"app.yhyue.com/moapp/jypkg/middleground"
+
 	. "app.yhyue.com/moapp/jybase/es"
 	"app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mysql"
@@ -53,7 +54,7 @@ var (
 	ClickhouseConn    driver.Conn
 )
 
-func init() {
+func InitConf() {
 	conf.MustLoad(*configFile, &C)
 	log.Println("初始化配置") //
 

+ 1 - 0
api/crmapplication.go

@@ -17,6 +17,7 @@ import (
 )
 
 func main() {
+	InitConf()
 	//注册代理服务
 	closeNotify, err := node.NewNode(C.Gateway.Etcd...).Register(C.Gateway.ServerCode, mc.InterfaceToStr(C.Port))
 	if err != nil {

+ 2 - 2
api/internal/handler/coophistorylisthandler.go

@@ -18,11 +18,11 @@ func CoopHistoryListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 		}
 
 		l := logic.NewCoopHistoryListLogic(r.Context(), svcCtx)
-		err := l.CoopHistoryList(&req)
+		resp, err := l.CoopHistoryList(&req)
 		if err != nil {
 			httpx.ErrorCtx(r.Context(), w, err)
 		} else {
-			httpx.Ok(w)
+			httpx.OkJsonCtx(r.Context(), w, resp)
 		}
 	}
 }

+ 2 - 2
api/internal/handler/projectlisthandler.go

@@ -18,11 +18,11 @@ func projectListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 		}
 
 		l := logic.NewProjectListLogic(r.Context(), svcCtx)
-		err := l.ProjectList(&req)
+		resp, err := l.ProjectList(&req)
 		if err != nil {
 			httpx.ErrorCtx(r.Context(), w, err)
 		} else {
-			httpx.Ok(w)
+			httpx.OkJsonCtx(r.Context(), w, resp)
 		}
 	}
 }

+ 2 - 2
api/internal/handler/prpnameasshandler.go

@@ -18,11 +18,11 @@ func PrPnameAssHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 		}
 
 		l := logic.NewPrPnameAssLogic(r.Context(), svcCtx)
-		err := l.PrPnameAss(&req)
+		resp, err := l.PrPnameAss(&req)
 		if err != nil {
 			httpx.ErrorCtx(r.Context(), w, err)
 		} else {
-			httpx.Ok(w)
+			httpx.OkJsonCtx(r.Context(), w, resp)
 		}
 	}
 }

+ 9 - 8
api/internal/service/employService.go

@@ -1,6 +1,12 @@
 package service
 
 import (
+	"database/sql"
+	"fmt"
+	"log"
+	"strings"
+	"time"
+
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/date"
 	elastic "app.yhyue.com/moapp/jybase/es"
@@ -8,13 +14,8 @@ import (
 	MC "bp.jydev.jianyu360.cn/CRM/application/api/common"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
 	"bp.jydev.jianyu360.cn/CRM/application/entity"
-	"database/sql"
-	"fmt"
 	"github.com/RoaringBitmap/roaring"
 	"github.com/gogf/gf/v2/util/gconv"
-	"log"
-	"strings"
-	"time"
 )
 
 const (
@@ -898,9 +899,9 @@ func EmployHandle(valueMap map[string]interface{}, employData map[string]interfa
 		clueSql := ""
 		chanceSql := ""
 		if positionType == 0 {
-			customSql = fmt.Sprintf("select  COUNT(1) from  %s where  %s  in (%s) and  position_id=?", entity.CUSTOM, findKey, employArrStr, positionId)
-			clueSql = fmt.Sprintf("select  COUNT(1) from  %s where employ_info_id  in (%s) and  position_id=?", entity.SALE_CLUE, employArrStr, positionId)
-			chanceSql = fmt.Sprintf("select  COUNT(1) from  %s where employ_info_id  in (%s) and  position_id=?", entity.SALE_CHANCE, employArrStr, positionId)
+			customSql = fmt.Sprintf("select  COUNT(1) from  %s where  %s  in (%s) and  position_id=%d", entity.CUSTOM, findKey, employArrStr, positionId)
+			clueSql = fmt.Sprintf("select  COUNT(1) from  %s where employ_info_id  in (%s) and  position_id=%d", entity.SALE_CLUE, employArrStr, positionId)
+			chanceSql = fmt.Sprintf("select  COUNT(1) from  %s where employ_info_id  in (%s) and  position_id=%d", entity.SALE_CHANCE, employArrStr, positionId)
 		} else {
 			customSql = fmt.Sprintf("select  COUNT(1) from  %s where  %s  in (%s)", entity.CUSTOM, findKey, employArrStr)
 			clueSql = fmt.Sprintf("select  COUNT(1) from  %s where employ_info_id  in (%s)", entity.SALE_CLUE, employArrStr)

+ 12 - 16
api/internal/service/network.go

@@ -32,7 +32,7 @@ func (n *Network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
 		itype = 5
 	}
 	nowFormat := NowFormat(Date_Full_Layout)
-	var getValues = func(cid int64) []interface{} {
+	var saveIntroduce = func(tx *sql.Tx, cid int64) int64 {
 		values := []interface{}{}
 		if in.Introduce_owner_id != "" {
 			for k, v := range strings.Split(in.Introduce_owner_id, ",") {
@@ -41,20 +41,20 @@ func (n *Network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
 		}
 		if in.Introduce_project_id != "" {
 			for k, v := range strings.Split(in.Introduce_project_id, ",") {
-				values = append(values, in.PositionId, in.EntId, in.EntDeptId, in.EntUserId, cid, v, strings.Split(in.Introduce_project_name, ",")[k], 1, nowFormat)
+				values = append(values, in.PositionId, in.EntId, in.EntDeptId, in.EntUserId, cid, v, strings.Split(in.Introduce_project_name, ",")[k], 2, nowFormat)
 			}
 		}
-		return values
+		var r3 int64
+		if len(values) > 0 {
+			_, r3 = CrmMysql.InsertBatchByTx(tx, "connection_introduce", []string{"position_id", "ent_id", "ent_dept_id", "ent_user_id", "connection_id", "relate_id", "relate_name", "itype", "create_time"}, values)
+		}
+		return r3
 	}
 	if in.Id > 0 {
 		if CrmMysql.ExecTx("更新人脉", func(tx *sql.Tx) bool {
-			r1 := CrmMysql.UpdateOrDeleteBySqlByTx(`update 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)
-			r2 := CrmMysql.UpdateOrDeleteBySqlByTx(`delete from connection_introduce where connection_id=? and position_id=?`, in.Id, in.PositionId)
-			var r3 int64
-			if len(values) > 0 {
-				_, r3 = CrmMysql.InsertBatchByTx(tx, "connection_introduce", []string{"connection_id", "relate_id", "relate_name", "itype", "create_time"}, getValues(r1))
-			}
-			return r1 > 0 && r2 >= 0 && r3 >= 0
+			r1 := CrmMysql.UpdateOrDeleteBySqlByTx(tx, `update 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)
+			r2 := CrmMysql.UpdateOrDeleteBySqlByTx(tx, `delete from connection_introduce where connection_id=? and position_id=?`, in.Id, in.PositionId)
+			return r1 > 0 && r2 >= 0 && saveIntroduce(tx, in.Id) >= 0
 		}) {
 			reply.Data = map[string]interface{}{
 				"status": 1,
@@ -67,12 +67,8 @@ func (n *Network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
 	} else {
 		id := 0
 		if CrmMysql.ExecTx("新增人脉", func(tx *sql.Tx) bool {
-			_, r1 := CrmMysql.InsertBatchByTx(tx, "connection", []string{"position_id", "ent_id", "ent_dept_id", "ent_user_id", "itype", "company_name", "company_id", "position_id", "contact_name", "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})
-			var r2 int64
-			if len(values) > 0 {
-				_, r2 = CrmMysql.InsertBatchByTx(tx, "connection_introduce", []string{"position_id", "ent_id", "ent_dept_id", "ent_user_id", "connection_id", "relate_id", "relate_name", "itype", "create_time"}, values)
-			}
-			return r1 > 0 && r2 >= 0
+			_, r1 := CrmMysql.InsertBatchByTx(tx, "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})
+			return r1 > 0 && saveIntroduce(tx, r1) >= 0
 		}) {
 			reply.Data = map[string]interface{}{
 				"status": 1,

+ 9 - 8
api/internal/service/network_test.go

@@ -20,19 +20,20 @@ func initDb() {
 	}
 	CrmMysql.Init()
 }
-func TestDeduction(t *testing.T) {
+func TestAddOrUpdate(t *testing.T) {
 	initDb()
 	res := VarNetwork.AddOrUpdate(&types.AddOrUpdateReq{
 		PositionId:             943,
-		Company_id:             "123456",
-		Company_name:           "王传进的测试企业",
-		Contact_person:         "王传进",
+		Company_id:             "112233445566",
+		Company_name:           "王传进的测试企业1",
+		Contact_person:         "王传进1",
 		Contact_phone:          "15037870765",
-		Introduce_owner_id:     "1,2,3",
-		Introduce_owner_name:   "a,b,c",
-		Introduce_project_id:   "4,5,6",
-		Introduce_project_name: "d,e,f",
+		Introduce_owner_id:     "11,22,33",
+		Introduce_owner_name:   "aa,bb,cc",
+		Introduce_project_id:   "44,55,66",
+		Introduce_project_name: "dd,ee,ff",
 		Type:                   "middleman",
+		Id:                     1,
 	})
 	log.Println(res)
 }

+ 70 - 11
api/internal/service/plistService.go

@@ -1,16 +1,20 @@
 package service
 
 import (
+	"context"
 	"fmt"
 	"strings"
 
 	"app.yhyue.com/moapp/jybase/common"
 	P "app.yhyue.com/moapp/jybase/mapping"
+	T "bp.jydev.jianyu360.cn/CRM/application/api/common"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
 )
 
 const (
 	pageSize = 100
+
+	sql_1 = `SELECT count(1) FROM information.transaction_info WHERE buyer_id = ?`
 )
 
 type ProjectData struct {
@@ -23,15 +27,17 @@ type ProjectEntry struct {
 	projectName string
 }
 
-func GetProjectList(req *types.ProjectListReq) (resultList []interface{}, hasNextPage bool, total int) {
+func GetProjectList(req *types.ProjectListReq) (resultList *[]map[string]interface{}, hasNextPage bool, total int) {
 
 	getSql(req)
 
-	total = len(resultList)
-	if total > pageSize {
-		resultList = resultList[:pageSize]
-		hasNextPage = true
-	}
+	//get(req, resultList)
+	//
+	//total = len(resultList)
+	//if total > pageSize {
+	//	resultList = resultList[:pageSize]
+	//	hasNextPage = true
+	//}
 	return
 }
 
@@ -125,10 +131,63 @@ func getSql(req *types.ProjectListReq) (countSql, findSql string) {
 		}
 		querys = append(querys, fmt.Sprintf(" a.property_form in (%s) ", strings.Join(arr, ",")))
 	}
-	userStr := ""
-	//查询数量
-	countSql = fmt.Sprintf("select count(1) as count from %s  a  where  %s   %s", "", userStr, strings.Join(querys, " and "))
-	//列表查询语句
-	findSql = "select a.id,a.date,a.infoid,a.matchways,a.isvisit,REPLACE(a.matchkeys,'+',' ') as matchkeys,a.type,a.attachment_count"
+	findSql = "select a.project_id,a.project_name,a.project_budget,a.project_money,a.business_type,a.buyer"
 	return
 }
+
+// @Author jianghan
+// @Description 处理状态/我的人脉
+// @Date 2024/4/17
+func get(req *types.ProjectListReq, list []map[string]interface{}) (result []map[string]interface{}) {
+	field := "is_handle,is_ignore,is_create"
+	for _, m := range list {
+		query := map[string]interface{}{
+			"position_id": req.PositionId,
+			"relate_id":   common.ObjToString(m["project_id"]),
+			"itype":       2,
+		}
+		info := T.CrmMysql.FindOne("connection_status", query, field, "")
+		if info != nil && len(*info) > 0 {
+			m["is_handle"] = (*info)["is_handle"]
+			m["is_ignore"] = (*info)["is_ignore"]
+			m["is_create"] = (*info)["is_create"]
+		}
+
+		// 人脉、人脉所在单位项目 conn_type: 1/人脉可转介绍项目 conn_type: 2
+		field1 := ""
+		query1 := map[string]interface{}{
+			"position_id": req.PositionId,
+			"company_id":  common.ObjToString(m["buyer_id"]),
+			"status":      1,
+		}
+		info1 := T.CrmMysql.FindOne("connection", query1, field1, "")
+		if info1 != nil && len(*info1) > 0 {
+			m["my_conn"] = true
+			m["conn_type"] = 1
+		} else {
+			m["my_conn"] = false
+		}
+		if m["conn_type"] != nil {
+			query2 := map[string]interface{}{
+				"company_id": common.ObjToString(m["buyer_id"]),
+			}
+			info2 := T.CrmMysql.FindOne("connection", query2, field1, "")
+			if info2 != nil && len(*info2) > 0 {
+				m["conn_type"] = 1
+			} else {
+				m["conn_type"] = 2
+			}
+		}
+		// 转介绍成功率高标签
+		count := 0
+		err := T.ClickhouseConn.QueryRow(context.TODO(), sql_1, common.ObjToString(m["buyer_id"])).Scan(&count)
+		if err != nil && count > 2 {
+			m["high_success"] = true
+		} else {
+			m["high_success"] = false
+		}
+
+	}
+
+	return list
+}

+ 5 - 1
api/internal/types/types.go

@@ -203,6 +203,10 @@ type CanAddReq struct {
 }
 
 type ProjectListReq struct {
+	PositionId   int64  `header:"positionId,optional"`
+	EntId        string `header:"entId,optional"`
+	EntUserId    string `header:"entUserId,optional"`
+	DeptId       string `header:"deptId,optional"` //部门id
 	PageNum      int64  `json:"pageNum"`
 	PageSize     int64  `json:"pageSize"`
 	BusinessType string `json:"businessType"`
@@ -239,7 +243,7 @@ type AddOrUpdateReq struct {
 	Introduce_owner_name   string `json:"introduce_owner_name,optional"`
 	Introduce_project_id   string `json:"introduce_project_id,optional"`
 	Introduce_project_name string `json:"introduce_project_name,optional"`
-	Id                     string `json:"id,optional"`
+	Id                     int64  `json:"id,optional"`
 	Type                   string `json:"type,optional"`
 }
 

+ 6 - 0
api/logs/access.log

@@ -0,0 +1,6 @@
+{"@timestamp":"2024-04-17T18:01:25.448+08:00","caller":"common/initconfig.go:70","content":"info--日志记录","level":"info"}
+{"@timestamp":"2024-04-17T18:01:25.448+08:00","caller":"common/initconfig.go:70","content":"error--日志记录","level":"info"}
+{"@timestamp":"2024-04-17T18:01:25.624+08:00","caller":"common/initconfig.go:125","content":"--初始化 mongodb--","level":"info"}
+{"@timestamp":"2024-04-17T18:01:25.625+08:00","caller":"common/initconfig.go:134","content":"--初始化 mongodb Bidding --","level":"info"}
+{"@timestamp":"2024-04-17T18:01:25.625+08:00","caller":"common/initconfig.go:145","content":"--初始化 mongodb ent --","level":"info"}
+{"@timestamp":"2024-04-17T18:01:25.626+08:00","caller":"common/initconfig.go:156","content":"--初始化 mongodb ent --","level":"info"}

+ 0 - 0
api/logs/error.log


+ 0 - 0
api/logs/severe.log


+ 0 - 0
api/logs/slow.log


+ 0 - 0
api/logs/stat.log