Jelajahi Sumber

标讯数据操作

WH01243 1 tahun lalu
induk
melakukan
f8d251fb85
7 mengubah file dengan 73 tambahan dan 34 penghapusan
  1. 6 3
      entity/entity.go
  2. 1 0
      rpc/biservice.go
  3. 1 0
      rpc/etc/biservice.yaml
  4. 1 0
      rpc/internal/config/config.go
  5. 2 24
      service/clue.go
  6. 1 4
      service/exprot.go
  7. 61 3
      service/operate.go

+ 6 - 3
entity/entity.go

@@ -47,8 +47,9 @@ var (
 		"07": "待签署客户",
 		"08": "成交客户",
 	}
-	PublicKey = ""
-	GmailAuth []*mail.GmailAuth
+	PublicKey        = ""
+	GmailAuth        []*mail.GmailAuth
+	UpdataProjectUrl string
 )
 
 type HlyjS struct {
@@ -222,10 +223,12 @@ func (h *Handler) HandleMessage(m *nsq.Message) error {
 }
 
 // 初始化reidis
+func InitUrl(url string) {
+	UpdataProjectUrl = url
+}
 func InitRedis(redisAddr []string) {
 	redis.InitRedisBySize(strings.Join(redisAddr, ","), 100, 30, 300)
 }
-
 func GetHlyj(appid, account, secret, tokenUrl, callUrl, integratedid string, callFlag int) {
 	Hlyj = &HlyjS{
 		Appid:        appid,

+ 1 - 0
rpc/biservice.go

@@ -36,6 +36,7 @@ func main() {
 	entity.InitEntEs(c.EntEs.Version, c.EntEs.Address, c.EntEs.UserName, c.EntEs.Password, c.EntEs.DbSize)
 	entity.InitArea()
 	entity.InitRedis(c.RedisAddress)
+	entity.InitUrl(c.UpdateProjectUrl)
 	//合力亿捷
 	entity.GetHlyj(c.Hlyj.Appid, c.Hlyj.Account, c.Hlyj.Secret, c.Hlyj.TokenUrl, c.Hlyj.CallUrl, c.Hlyj.Integratedid, c.Hlyj.CallFlag)
 	//nsq

+ 1 - 0
rpc/etc/biservice.yaml

@@ -113,3 +113,4 @@ Mail:
     Port: 465
     Pwd: "ue9Rg9Sf4CVtdm5a"
     User: "public03@topnet.net.cn"
+UpdateProjectUrl: "https://tieta.spdata.jianyu360.com/updateProject"

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

@@ -72,4 +72,5 @@ type Config struct {
 		Pwd  string
 		User string
 	}
+	UpdateProjectUrl string
 }

+ 2 - 24
service/clue.go

@@ -1,7 +1,6 @@
 package service
 
 import (
-	"bytes"
 	"context"
 	"database/sql"
 	"encoding/json"
@@ -114,7 +113,7 @@ func ClueImportTtSync(this *biservice.ClueImportReq) (string, int) {
 	}
 }
 
-//根据id重新生成es
+// 根据id重新生成es
 func CreateEsById(newId string) bool {
 	data := BiService.FindOne("customer_data_ttzl", map[string]interface{}{"id_new": newId}, "", "")
 	if data == nil || len(*data) == 0 {
@@ -125,7 +124,7 @@ func CreateEsById(newId string) bool {
 	return ok
 }
 
-//重新生成es
+// 重新生成es
 func CreateEs(v map[string]interface{}) (string, bool) {
 	details := ""
 	biddingData, ok := Bidding.FindOne("bidding", map[string]interface{}{"_id": mongodb.StringTOBsonId(common.ObjToString(v["id"]))})
@@ -1135,24 +1134,3 @@ 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
-}

+ 1 - 4
service/exprot.go

@@ -3,6 +3,7 @@ package service
 import (
 	"app.yhyue.com/moapp/jybase/mail"
 	"archive/zip"
+	. "bp.jydev.jianyu360.cn/BaseService/biService/entity"
 	"fmt"
 	"github.com/gogf/gf/v2/util/gconv"
 	"github.com/xuri/excelize/v2"
@@ -14,10 +15,6 @@ import (
 	"time"
 )
 
-import (
-	. "bp.jydev.jianyu360.cn/BaseService/biService/entity"
-)
-
 type ExportReq struct {
 	Mail       string
 	Mapping    []string

+ 61 - 3
service/operate.go

@@ -1,16 +1,74 @@
 package service
 
+import (
+	. "bp.jydev.jianyu360.cn/BaseService/biService/entity"
+	"bytes"
+	"encoding/json"
+	"io/ioutil"
+	"log"
+	"net/http"
+)
+
 type Operate struct {
 	NewId       string
 	OperateType int64
 }
 
-func (a *Operate) InfoOperate() {
-	//
+func (a *Operate) InfoOperate() bool {
+	//数据查询
+	data := BiService.FindOne("customer_data_ttzl", map[string]interface{}{"id_new": a.NewId}, "", "")
+	if data == nil || len(*data) == 0 {
+		log.Println("没有找到该数据", a.NewId)
+		return false
+	}
+	sendParam := map[string]interface{}{
+		"type": a.OperateType,
+	}
 	if a.OperateType == 0 {
 		//修改
-
+		_, ok := CreateEs(*data)
+		if !ok {
+			return false
+		}
+		sendParam["nid"] = a.NewId
 	} else {
 		//删除
+		//清除mysql数据
+		if BiService.Delete("customer_data_ttzl", map[string]interface{}{"id_new": a.NewId}) {
+			//清除es数据
+			Es.DelById("ttbid", "ttbid", a.NewId)
+		} else {
+			return false
+		}
+		projectId := (*data)["projectId"]
+		if projectId == "" {
+			return true
+		}
+		sendParam["nid"] = projectId
+	}
+	marshalData, _ := json.Marshal(sendParam)
+	DoPost(UpdataProjectUrl, marshalData)
+	return true
+
+}
+
+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
 }