Jianghan 1 ano atrás
pai
commit
e38d6a78a8
1 arquivos alterados com 30 adições e 9 exclusões
  1. 30 9
      api/internal/service/CoopHistoryService.go

+ 30 - 9
api/internal/service/CoopHistoryService.go

@@ -9,6 +9,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"github.com/zeromicro/go-zero/core/logx"
+	"time"
 )
 
 var (
@@ -16,6 +17,7 @@ var (
 	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 IN ? 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 = `{
 	  "query": {
 		"bool": {
@@ -23,19 +25,19 @@ var (
 			{
 			  "range": {
 				"zbtime": {
-				  "gte": 123
+				  "gte": %d
 				}
 			  }
 			},
 			{
 			  "term": {
-				"buyer_id": "123"
+				"buyer_id": %s
 			  }
 			}
 		  ],
 		  "must_not": {
 			"term": {
-			  "property_form": "123123"
+			  "property_form": %s
 			}
 		  }
 		}
@@ -99,7 +101,7 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData) {
 
 	// 1、同甲异业数据/招标代理机构渠道
 	if propertyForm != "" {
-		r1, r2 := getData(propertyForm, common.ObjToString(pMap["buyer_id"]))
+		r1, r2 := GetData(propertyForm, common.ObjToString(pMap["buyer_id"]))
 		if r1 != nil && len(r1) > 0 {
 			tmp := &ResultData{
 				channelType: 1,
@@ -120,7 +122,7 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData) {
 		}
 	}
 	// 中间人可介绍业主
-	r3 := getData1(req)
+	r3 := GetData1(req.PositionId, common.ObjToString(pMap["buyer_id"]))
 	if r3 != nil && len(r3) > 0 {
 		tmp := &ResultData{
 			channelType: 1,
@@ -130,12 +132,15 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData) {
 		}
 		result = append(result, tmp)
 	}
+	// 关联单位
+	GetData2(common.ObjToString(pMap["buyer_id"]))
 
 	return
 }
 
-func getData(propertyForm, bid string) (result1, result2 []map[string]interface{}) {
-	aggs, count, res := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query, 1, propertyForm, bid))
+func GetData(propertyForm, bid string) (result1, result2 []map[string]interface{}) {
+	timestamp := time.Now().AddDate(-3, 0, 0).Unix()
+	aggs, count, res := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query, timestamp, propertyForm, bid))
 	logx.Info("es聚合查询结果:", aggs, count, res)
 	type AggStruct struct {
 		Buckets []struct {
@@ -231,8 +236,24 @@ func getData(propertyForm, bid string) (result1, result2 []map[string]interface{
 	return
 }
 
-func getData1(req *types.CoopHistoryReq) (result []map[string]interface{}) {
-	info := T.CrmMysql.SelectBySql(sql_2_2, req.PositionId, req.Pid)
+// @Author jianghan
+// @Description 中间人
+// @Date 2024/4/20
+func GetData1(positionId int64, buyid string) (result []map[string]interface{}) {
+	info := T.CrmMysql.SelectBySql(sql_2_2, positionId, buyid)
+	if info != nil && len(*info) > 0 {
+		for _, m := range *info {
+			result = append(result, map[string]interface{}{"name": m["company_name"], "pserson": m["contact_name"]})
+		}
+	}
+	return
+}
+
+// @Author jianghan
+// @Description 业主关联企业 上下级/股权控制
+// @Date 2024/4/20
+func GetData2(buyid string) (result []map[string]interface{}) {
+	info := T.CrmMysql.SelectBySql(sql_2_3, buyid, buyid, buyid, buyid, buyid, buyid)
 	if info != nil && len(*info) > 0 {
 		for _, m := range *info {
 			result = append(result, map[string]interface{}{"name": m["company_name"], "pserson": m["contact_name"]})