Jianghan 1 anno fa
parent
commit
3921d7ec2a

+ 9 - 20
api/application.api

@@ -215,15 +215,15 @@ type (
 		PageSize     int64  `json:"pageSize"`
 		BusinessType string `json:"businessType"`
 		SaleStatus   int    `json:"saleStatus"`
-		ProjectName  string `json:"projectName"`
-		StartTime    int64  `json:"startTime"`
-		EntTime      int64  `json:"entTime"`
-		Area         string `json:"area"`
-		City         string `json:"city"`
-		District     string `json:"district"`
-		PropertyForm string `json:"propertyForm"`
-		SubClass     string `json:"subClass"`
-		Amount       string `json:"amount"`
+		ProjectName  string `json:"projectName,optional"`
+		StartTime    int64  `json:"startTime,optional"`
+		EntTime      int64  `json:"entTime,optional"`
+		Area         string `json:"area,optional"`
+		City         string `json:"city,optional"`
+		District     string `json:"district,optional"`
+		PropertyForm string `json:"propertyForm,optional"`
+		SubClass     string `json:"subClass,optional"`
+		Amount       string `json:"amount,optional"`
 	}
 	PnameAssReq {
 		ProjectName string `json:"projectName"`
@@ -293,13 +293,6 @@ type (
 	InfoDetailReq {
 		InfoId string `json:"infoId"`
 	}
-	PListPathReq {
-		PositionId int64  `header:"positionId"`
-		EntUserId  int64  `header:"entUserId,optional"`
-		EntId      int64  `header:"entId,optional"`
-		EntDeptId  int64  `header:"entDeptId,optional"`
-		BuyerId    string `json:"buyerId"`
-	}
 	PrjectHistoryReq {
 		BuyerId  string `json:"buyerId"`
 		WinnerId string `json:"winnerId"`
@@ -399,10 +392,6 @@ service crmApplication {
 	@handler infoDetail
 	post /crmApplication/infomation/detail (InfoDetailReq) returns (Reply)
 
-	@doc "人脉可达商机列表-人脉路径"
-	@handler plistPath
-	post /crmApplication/network/plist/pathway (PListPathReq) returns (Reply)
-
 	@doc "人脉项目分析-业主合作历史"
 	@handler projectHistory
 	post /crmApplication/pr/project/history (PrjectHistoryReq) returns (Reply)

+ 0 - 28
api/internal/handler/plistpathhandler.go

@@ -1,28 +0,0 @@
-package handler
-
-import (
-	"net/http"
-
-	"bp.jydev.jianyu360.cn/CRM/application/api/internal/logic"
-	"bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
-	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
-	"github.com/zeromicro/go-zero/rest/httpx"
-)
-
-func plistPathHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
-	return func(w http.ResponseWriter, r *http.Request) {
-		var req types.PListPathReq
-		if err := httpx.Parse(r, &req); err != nil {
-			httpx.ErrorCtx(r.Context(), w, err)
-			return
-		}
-
-		l := logic.NewPlistPathLogic(r.Context(), svcCtx)
-		resp, err := l.PlistPath(&req)
-		if err != nil {
-			httpx.ErrorCtx(r.Context(), w, err)
-		} else {
-			httpx.OkJsonCtx(r.Context(), w, resp)
-		}
-	}
-}

+ 0 - 5
api/internal/handler/routes.go

@@ -97,11 +97,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				Path:    "/crmApplication/network/networkList",
 				Handler: networkListHandler(serverCtx),
 			},
-			{
-				Method:  http.MethodPost,
-				Path:    "/crmApplication/network/plist/pathway",
-				Handler: plistPathHandler(serverCtx),
-			},
 			{
 				Method:  http.MethodPost,
 				Path:    "/crmApplication/network/project/list",

+ 0 - 32
api/internal/logic/plistpathlogic.go

@@ -1,32 +0,0 @@
-package logic
-
-import (
-	"bp.jydev.jianyu360.cn/CRM/application/service"
-	"context"
-
-	"bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
-	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
-
-	"github.com/zeromicro/go-zero/core/logx"
-)
-
-type PlistPathLogic struct {
-	logx.Logger
-	ctx    context.Context
-	svcCtx *svc.ServiceContext
-}
-
-func NewPlistPathLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PlistPathLogic {
-	return &PlistPathLogic{
-		Logger: logx.WithContext(ctx),
-		ctx:    ctx,
-		svcCtx: svcCtx,
-	}
-}
-
-func (l *PlistPathLogic) PlistPath(req *types.PListPathReq) (resp *types.Reply, err error) {
-
-	service.ConnectionsHandle([]string{req.BuyerId}, req.PositionId, true)
-
-	return
-}

+ 5 - 1
api/internal/logic/projecthistorylogic.go

@@ -27,7 +27,11 @@ func NewProjectHistoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Pr
 func (l *ProjectHistoryLogic) ProjectHistory(req *types.PrjectHistoryReq) (resp *types.Reply, err error) {
 	resp = &types.Reply{}
 	if req.BuyerId != "" && req.WinnerId != "" {
-		resp.Data = service.GetData3(req.BuyerId, req.WinnerId)
+		data := service.GetData3(req.BuyerId, req.WinnerId)
+		resp.Data = map[string]interface{}{
+			"count": len(data),
+			"list":  data,
+		}
 	} else {
 		resp.Error_code = -1
 		resp.Error_msg = "参数有误"

+ 13 - 7
api/internal/service/CoopHistoryService.go

@@ -15,7 +15,7 @@ import (
 var (
 	INDEX_1  = "transaction_info"
 	sql_2_0  = `SELECT buyer, buyer_id, agency, agency_id, property_form FROM information.transaction_info WHERE project_id = ?`
-	sql_2_1  = `SELECT project_id, project_name, zbtime FROM information.transaction_info WHERE buyer_id = ? AND winner winner_id IN ? ORDER BY zbtime DESC`
+	sql_2_1  = `SELECT project_id, project_name, zbtime FROM information.transaction_info WHERE buyer_id = ? AND has(winner_id, ?) ORDER BY zbtime DESC`
 	sql_2_2  = `SELECT b.company_id, b.company_name, b.contact_name, a.relate_id, a.relate_name FROM connection_introduce a INNER JOIN connection b ON b.position_id =%d AND a.connection_id = b.id AND b.state = 1 AND a.itype = 1 AND b.itype = 4 AND a.relate_Id = %s`
 	sql_2_3  = `select a.a_id as a_id, a.b_id as b_id, a.a_name as a_name, a.b_name as b_name, a.code as code, c.legal_person as c_person, d.legal_person d_person from ent_map_code a left join ent_info c on (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201') and a.a_id = c.id left join ent_info d on (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201') and a.b_id = d.id where (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201')`
 	es_query = `{
@@ -239,15 +239,21 @@ func GetData2(buyid string) (result []map[string]interface{}) {
 	return
 }
 
+type P_History struct {
+	ProjectId   string `ch:"project_id"`
+	ProjectName string `ch:"project_name"`
+	ZbTime      int64  `ch:"zbtime"`
+}
+
 // @Author jianghan
 // @Description 合作历史
 // @Date 2024/4/20
-func GetData3(buyerId, winnerId string) (result []map[string]interface{}) {
-	rows, err := T.ClickhouseConn.Query(context.TODO(), sql_2_1, buyerId, winnerId)
-	for err != nil && rows.Next() {
-		m := make(map[string]interface{})
-		rows.Scan(&m)
-		result = append(result, m)
+func GetData3(buyerId, winnerId string) (result []*P_History) {
+	rows, _ := T.ClickhouseConn.Query(context.TODO(), sql_2_1, buyerId, winnerId)
+	for rows.Next() {
+		pHis := P_History{}
+		_ = rows.ScanStruct(&pHis)
+		result = append(result, &pHis)
 	}
 	return
 }

+ 53 - 46
api/internal/service/plistService.go

@@ -18,7 +18,6 @@ const (
 
 	sql_1 = `SELECT count(1) FROM information.transaction_info WHERE buyer_id = ?`
 	sql_2 = `SELECT relate_id, is_handle, is_ignore, is_create FROM crm.connection_status WHERE position_id = ? AND itype = 2`
-	sql_3 = `SELECT b.company_id, b.company_name, b.contact_name, a.relate_id, a.relate_name FROM connection_introduce a INNER JOIN connection b ON b.position_id =%d ND a.connection_id = b.idAND b.state = 1AND a.type = 1AND b.type = 4AND a.relate_Id = %s`
 )
 
 type ProjectData struct {
@@ -28,42 +27,48 @@ type ProjectData struct {
 }
 
 type ProjectEntry struct {
-	projectName  string
-	buyer        string
-	buyerId      string
-	sWinner      string
-	area         string
-	city         string
-	district     string
-	startTime    int64
-	entTime      int64
-	subClass     string
-	propertyForm string
-	businessType string
+	ProjectId   string   `ch:"project_id"`
+	projectName string   `ch:"project_name"`
+	Buyer       string   `ch:"buyer"`
+	BuyerId     string   `ch:"buyer_id"`
+	Winner      []string `ch:"winner"`
+	Area        string   `ch:"area"`
+	city        string   `ch:"city"`
+	District    string   `ch:"district"`
+	ZbTime      int64    `ch:"zbtime"`
+	EndTime     int64    `ch:"endtime"`
+	IsHandle    int      `json:"is_handle"`
+	IsIgnore    int      `json:"is_ignore"`
+	IsCreate    int      `json:"is_create"`
+	MyConn      bool     `json:"my_conn"`
+	ConnType    int      `json:"conn_type"`
+	HighSuccess bool     `json:"high_success"`
 }
 
-func GetProjectList(req *types.ProjectListReq) (resultList []map[string]interface{}, hasNextPage bool, total int) {
+func GetProjectList(req *types.ProjectListReq) (resultList []*ProjectEntry, hasNextPage bool, total int) {
 
 	buyerM := service.BuyerList(req.PartyA, req.Supplier, req.Heterotophy, req.Intermediary, req.Agency)
 	service.MonitorStatusInit(req.PositionId, buyerM, "0")
+	buyerArr := make([]string, len(*buyerM))
+	for b := range *buyerM {
+		buyerArr = append(buyerArr, b)
+	}
 
 	preSales := preSalesStatus(req.PositionId)
 	isSqlPage := false
 	if req.SaleStatus == 0 {
 		isSqlPage = true // 是否sql分页
 	}
-	findSql := getQuerySql(req, isSqlPage)
+	findSql := getQuerySql(req, isSqlPage, buyerArr)
 	rows, err := T.ClickhouseConn.Query(context.TODO(), findSql)
 	defer rows.Close()
 	if err != nil {
 		return nil, false, 0
 	}
-	i := 0
-	info := make(map[string]interface{})
 	for rows.Next() {
-		rows.Scan(&info)
-		resultList = append(resultList, info)
-		i++
+		project := ProjectEntry{}
+		rows.Scan(&project)
+		resultList = append(resultList, &project)
 	}
 
 	filterData(req, resultList, preSales, isSqlPage)
@@ -102,11 +107,15 @@ func preSalesStatus(posid int64) (m1 map[string]interface{}) {
 	return m1
 }
 
-func getQuerySql(req *types.ProjectListReq, isPage bool) (findSql string) {
+func getQuerySql(req *types.ProjectListReq, isPage bool, buyerArr []string) (findSql string) {
 	querys := []string{}
+	// 左侧选中的业主id
+	if len(buyerArr) > 0 {
+		querys = append(querys, fmt.Sprintf(" a.buyer_id in (%s) ", strings.Join(buyerArr, ",")))
+	}
 	//	商机类型
 	if req.BusinessType != "" {
-		querys = append(querys, fmt.Sprintf(" a.business_type in (%s) ", req.BusinessType))
+		querys = append(querys, fmt.Sprintf(" a.business_type in ('%s') ", req.BusinessType))
 	}
 	if req.ProjectName != "" {
 		querys = append(querys, " a.projectname like '% "+req.ProjectName+"%'")
@@ -121,8 +130,6 @@ func getQuerySql(req *types.ProjectListReq, isPage bool) (findSql string) {
 	} else if req.StartTime == 0 && req.EntTime > 0 {
 		et := req.StartTime + 90*24*60*60
 		querys = append(querys, fmt.Sprintf(" a.endtime<=%d", et))
-	} else {
-		querys = append(querys, " a.endtime>0")
 	}
 	var regionArr = []string{}
 	if req.Area != "" || req.City != "" || req.District != "" {
@@ -192,7 +199,7 @@ func getQuerySql(req *types.ProjectListReq, isPage bool) (findSql string) {
 		}
 		querys = append(querys, fmt.Sprintf(" a.property_form in (%s) ", strings.Join(arr, ",")))
 	}
-	findSql = "select a.project_id,a.project_name,a.project_budget,a.project_money,a.business_type,a.buyer from"
+	findSql = "select a.project_id, a.project_name, a.buyer, a.buyer_id, a.winner, a.winner_id, a.area, a.city, a.district, a.zbtime, a.endtime "
 	findSql = fmt.Sprintf("%s from %s  a  where  %s ", findSql, "information.transaction_info", strings.Join(querys, " and "))
 	if isPage {
 		findSql += fmt.Sprintf(" limit %d,%d", (req.PageNum-1)*pageSize, pageSize)
@@ -203,8 +210,8 @@ func getQuerySql(req *types.ProjectListReq, isPage bool) (findSql string) {
 // @Author jianghan
 // @Description 过滤数据/补充销售机会状态信息,返回分页结果数据
 // @Date 2024/4/18
-func filterData(req *types.ProjectListReq, resultList []map[string]interface{}, preSales map[string]interface{}, isSqlPage bool) {
-	var newList []map[string]interface{}
+func filterData(req *types.ProjectListReq, resultList []*ProjectEntry, preSales map[string]interface{}, isSqlPage bool) {
+	var newList []*ProjectEntry
 	f := ""
 	v := 0
 	if req.SaleStatus == 1 {
@@ -218,10 +225,10 @@ func filterData(req *types.ProjectListReq, resultList []map[string]interface{},
 		v = 1
 	}
 	for _, m := range resultList {
-		if m1, ok := preSales[common.ObjToString(m["project_id"])].(map[string]interface{}); ok {
-			m["is_handle"] = m1["is_handle"]
-			m["is_ignore"] = m1["is_ignore"]
-			m["is_create"] = m1["is_create"]
+		if m1, ok := preSales[m.ProjectId].(map[string]interface{}); ok {
+			m.IsHandle = common.IntAll(m1["is_handle"])
+			m.IsIgnore = common.IntAll(m1["is_ignore"])
+			m.IsCreate = common.IntAll(m1["is_create"])
 			if !isSqlPage && m1[f] == v {
 				newList = append(newList, m)
 			}
@@ -235,46 +242,46 @@ func filterData(req *types.ProjectListReq, resultList []map[string]interface{},
 // @Author jianghan
 // @Description 补充人脉 等信息
 // @Date 2024/4/17
-func moreInfo(req *types.ProjectListReq, list []map[string]interface{}) (result []map[string]interface{}) {
+func moreInfo(req *types.ProjectListReq, list []*ProjectEntry) (result []*ProjectEntry) {
 	for _, m := range list {
-		// 人脉、人脉所在单位项目 conn_type: 1/人脉可转介绍项目 conn_type: 2
+		// 人脉、人脉所在单位项目 conn_type: 1 人脉可转介绍项目; conn_type: 2 人脉所在单位项目
 		field1 := ""
 		query1 := map[string]interface{}{
 			"position_id": req.PositionId,
-			"company_id":  common.ObjToString(m["buyer_id"]),
+			"company_id":  m.BuyerId,
 			"status":      1,
 		}
 		info1 := T.CrmMysql.FindOne("connection", query1, field1, "")
 		if info1 != nil && len(*info1) > 0 {
-			m["my_conn"] = true
-			m["conn_type"] = 1
+			m.MyConn = true // 我的人脉
+			m.ConnType = 1
 		} else {
-			m["my_conn"] = false
+			m.MyConn = false
 		}
-		if m["conn_type"] != nil {
+		if m.ConnType == 0 {
 			query2 := map[string]interface{}{
-				"company_id": common.ObjToString(m["buyer_id"]),
+				"company_id": m.BuyerId,
 			}
 			info2 := T.CrmMysql.FindOne("connection", query2, field1, "")
 			if info2 != nil && len(*info2) > 0 {
-				m["conn_type"] = 1
+				m.ConnType = 1
 			} else {
-				m["conn_type"] = 2
+				m.ConnType = 2
 			}
 		}
 		// 转介绍成功率高标签
 		count := 0
-		err := T.ClickhouseConn.QueryRow(context.TODO(), sql_1, common.ObjToString(m["buyer_id"])).Scan(&count)
+		err := T.ClickhouseConn.QueryRow(context.TODO(), sql_1, m.BuyerId).Scan(&count)
 		if err != nil && count > 2 {
-			m["high_success"] = true
+			m.HighSuccess = true
 		} else {
-			m["high_success"] = false
+			m.HighSuccess = false
 		}
 
 		// 人脉路径
 		// 有我的人脉标签时不需要查询人脉路径信息
-		if m["my_conn"] == false {
-			service.ConnectionsHandle([]string{common.ObjToString(m["buyer_id"])}, req.PositionId, false)
+		if m.MyConn == false {
+			service.ConnectionsHandle([]string{m.BuyerId}, req.PositionId, false)
 		}
 	}
 

+ 9 - 17
api/internal/types/types.go

@@ -232,14 +232,6 @@ type OwnerListReq struct {
 	PageIndex        int64  `json:"pageIndex,optional"`
 }
 
-type PListPathReq struct {
-	PositionId int64  `header:"positionId"`
-	EntUserId  int64  `header:"entUserId,optional"`
-	EntId      int64  `header:"entId,optional"`
-	EntDeptId  int64  `header:"entDeptId,optional"`
-	BuyerId    string `json:"buyerId"`
-}
-
 type PnameAssReq struct {
 	ProjectName string `json:"projectName"`
 }
@@ -263,15 +255,15 @@ type ProjectListReq struct {
 	PageSize     int64  `json:"pageSize"`
 	BusinessType string `json:"businessType"`
 	SaleStatus   int    `json:"saleStatus"`
-	ProjectName  string `json:"projectName"`
-	StartTime    int64  `json:"startTime"`
-	EntTime      int64  `json:"entTime"`
-	Area         string `json:"area"`
-	City         string `json:"city"`
-	District     string `json:"district"`
-	PropertyForm string `json:"propertyForm"`
-	SubClass     string `json:"subClass"`
-	Amount       string `json:"amount"`
+	ProjectName  string `json:"projectName,optional"`
+	StartTime    int64  `json:"startTime,optional"`
+	EntTime      int64  `json:"entTime,optional"`
+	Area         string `json:"area,optional"`
+	City         string `json:"city,optional"`
+	District     string `json:"district,optional"`
+	PropertyForm string `json:"propertyForm,optional"`
+	SubClass     string `json:"subClass,optional"`
+	Amount       string `json:"amount,optional"`
 }
 
 type PushMsgReq struct {