xuzhiheng 1 рік тому
батько
коміт
ae0fde69aa

+ 9 - 9
api/biService.api

@@ -55,19 +55,19 @@ type (
 
 	ClueAddReq {
 		Phone            string `json:"phone"`
-		Username         string `json:"username"`
+		Username         string `json:"username,optional"`
 		Source           string `json:"source"`
 		Status999        string `json:"status999"`
 		Owner            string `json:"owner"`
 		EmpNo            string `json:"empNo"`
-		Company          string `json:"company"`
-		IsPolicymaker    string `json:"isPolicymaker"`
-		BelongToIndustry string `json:"belongToIndustry"`
-		Job              string `json:"job"`
-		CustomerNeeds    string `json:"customerNeeds"`
-		BelongTo         string `json:"belongTo"`
-		WantGoods        string `json:"wantGoods"`
-		CustomerBudget   string `json:"customerBudget"`
+		Company          string `json:"company,optional"`
+		IsPolicymaker    string `json:"isPolicymaker,optional"`
+		BelongToIndustry string `json:"belongToIndustry,optional"`
+		Job              string `json:"job,optional"`
+		CustomerNeeds    string `json:"customerNeeds,optional"`
+		BelongTo         string `json:"belongTo,optional"`
+		WantGoods        string `json:"wantGoods,optional"`
+		CustomerBudget   string `json:"customerBudget,optional"`
 	}
 )
 

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

@@ -55,17 +55,17 @@ type ClueImportReq struct {
 
 type ClueAddReq struct {
 	Phone            string `json:"phone"`
-	Username         string `json:"username"`
+	Username         string `json:"username,optional"`
 	Source           string `json:"source"`
 	Status999        string `json:"status999"`
 	Owner            string `json:"owner"`
 	EmpNo            string `json:"empNo"`
-	Company          string `json:"company"`
-	IsPolicymaker    string `json:"isPolicymaker"`
-	BelongToIndustry string `json:"belongToIndustry"`
-	Job              string `json:"job"`
-	CustomerNeeds    string `json:"customerNeeds"`
-	BelongTo         string `json:"belongTo"`
-	WantGoods        string `json:"wantGoods"`
-	CustomerBudget   string `json:"customerBudget"`
+	Company          string `json:"company,optional"`
+	IsPolicymaker    string `json:"isPolicymaker,optional"`
+	BelongToIndustry string `json:"belongToIndustry,optional"`
+	Job              string `json:"job,optional"`
+	CustomerNeeds    string `json:"customerNeeds,optional"`
+	BelongTo         string `json:"belongTo,optional"`
+	WantGoods        string `json:"wantGoods,optional"`
+	CustomerBudget   string `json:"customerBudget,optional"`
 }

+ 1 - 0
rpc/etc/biservice.yaml

@@ -73,6 +73,7 @@ Logx:
   Path: logs
   Level: info #info|error|severe
   KeepDays: 100
+CustomerCol: customer_test
 AddCountLimit: 500
 DrawCountLimit: 1000
 TopicName: jy_position_sync

+ 1 - 0
rpc/internal/config/config.go

@@ -35,6 +35,7 @@ type Config struct {
 		Password string
 	}
 	Mode           string
+	CustomerCol    string
 	AddCountLimit  int
 	DrawCountLimit int
 	TopicName      string

+ 1 - 1
rpc/internal/logic/clueaddlogic.go

@@ -26,5 +26,5 @@ func NewClueAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClueAddLo
 func (l *ClueAddLogic) ClueAdd(in *pb.ClueAddReq) (*pb.AddProjectResp, error) {
 	// todo: add your logic here and delete this line
 
-	return service.ClueAdd(in), nil
+	return service.ClueAdd(in, l.svcCtx.Config.CustomerCol), nil
 }

+ 37 - 5
service/clue.go

@@ -1,6 +1,7 @@
 package service
 
 import (
+	"bytes"
 	"database/sql"
 	"encoding/json"
 	"fmt"
@@ -8,6 +9,7 @@ import (
 	"log"
 	"math"
 	"net/http"
+	"net/url"
 	"regexp"
 	"sync"
 	"time"
@@ -19,9 +21,12 @@ import (
 	"bp.jydev.jianyu360.cn/BaseService/biService/rpc/biservice"
 )
 
-func ClueAdd(this *biservice.ClueAddReq) *biservice.AddProjectResp {
+func ClueAdd(this *biservice.ClueAddReq, col string) *biservice.AddProjectResp {
 	status := 1
 	nowTime := time.Now().Format(date.Date_Full_Layout)
+	if this.Company == "" {
+		this.Company = this.Phone
+	}
 	saveMap := map[string]interface{}{
 		"unique_id":        this.Phone,
 		"phone":            this.Phone,
@@ -41,17 +46,23 @@ func ClueAdd(this *biservice.ClueAddReq) *biservice.AddProjectResp {
 		"createTime":       nowTime,
 		"lastUpdateTime":   nowTime,
 	}
-	dataStr, _ := json.Marshal(&saveMap)
 	token := getToken()
-	url := `https://a1.7x24cc.com/commonInte?flag=1007&account=N000000029739&accessToken=` + token + `&json={"dbType":"0001","customerList":[` + string(dataStr) + `]}`
+	updateData := map[string]interface{}{
+		"dbType":       "0001",
+		"customerList": []map[string]interface{}{saveMap},
+	}
+	dataByte, _ := json.Marshal(&updateData)
+	url := `https://a1.7x24cc.com/commonInte?flag=1007&account=N000000029739&accessToken=` + token + `&json=` + url.QueryEscape(string(dataByte))
 	bs, err := doGet(url)
 	if err != nil {
 		status = -1
 		log.Println("调用接口失败")
 	} else {
 		resMap := common.StringToMap(string(bs))
-		if resMap["success"].(bool) {
-			CallTidb.Insert("customer", saveMap)
+		if resMap["success"] != nil && resMap["success"].(bool) {
+			CallTidb.Insert(col, saveMap)
+		} else {
+			status = -1
 		}
 	}
 	return &biservice.AddProjectResp{
@@ -954,3 +965,24 @@ func doGet(url string) ([]byte, error) {
 	log.Println(url, "调用结果 ", string(bs))
 	return bs, nil
 }
+
+func doPost(url string, body []byte) ([]byte, error) {
+	req, err := http.NewRequest("POST", url, bytes.NewReader(body))
+	if err != nil {
+		return nil, err
+	}
+	req.Header.Add("Content-Type", "application/json;charset=utf-8")
+	resp, err := http.DefaultClient.Do(req)
+	if err != nil {
+		return nil, err
+	}
+	bs, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		return nil, err
+	}
+	defer func() {
+		_ = resp.Body.Close()
+	}()
+	log.Println(url, "调用结果 ", string(bs))
+	return bs, nil
+}