From 90ebefc0ce4306bdc96f34ea9503ca986a59bbe7 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 31 一月 2024 14:12:00 +0800
Subject: [PATCH] 客户列表grpc接口
---
api/v1/salesDetails.go | 51 ++++++++++++++++++++++++---------------------------
1 files changed, 24 insertions(+), 27 deletions(-)
diff --git a/api/v1/salesDetails.go b/api/v1/salesDetails.go
index 8b7e98a..bae4856 100644
--- a/api/v1/salesDetails.go
+++ b/api/v1/salesDetails.go
@@ -1,7 +1,6 @@
package v1
import (
- "aps_crm/conf"
"aps_crm/constvar"
"aps_crm/model"
"aps_crm/model/grpc_init"
@@ -16,9 +15,8 @@
"aps_crm/utils"
"github.com/gin-gonic/gin"
"github.com/shopspring/decimal"
- "google.golang.org/grpc"
- "google.golang.org/grpc/credentials/insecure"
"strconv"
+ "strings"
)
type SalesDetailsApi struct{}
@@ -239,25 +237,6 @@
ctx.Ok()
}
-var (
- ProductInventoryServiceConn *grpc.ClientConn
-)
-
-func InitProductInventoryServiceConn() {
- var err error
- ProductInventoryServiceConn, err = grpc.Dial(conf.Conf.GrpcServiceAddr.WMS, grpc.WithTransportCredentials(insecure.NewCredentials()))
- if err != nil {
- logx.Errorf("grpc dial product service error: %v", err.Error())
- return
- }
-}
-
-func CloseProductInventoryServiceConn() {
- if ProductInventoryServiceConn != nil {
- ProductInventoryServiceConn.Close()
- }
-}
-
// GetProductInventoryInfo
//
// @Tags SalesDetails
@@ -273,9 +252,13 @@
return
}
number := c.Param("number")
- client := product_inventory.NewProductInventoryServiceClient(ProductInventoryServiceConn)
+ client := product_inventory.NewProductInventoryServiceClient(grpc_init.ProductInventoryServiceConn)
info, err := client.GetInventoryProductInfo(ctx.GetCtx(), &product_inventory.GetInventoryProductInfoRequest{Number: number})
if err != nil {
+ if strings.Contains(err.Error(), "record not found") {
+ ctx.Ok()
+ return
+ }
logx.Errorf("GetProductInfo err: %v", err.Error())
ctx.FailWithMsg(ecode.UnknownErr, "grpc璋冪敤閿欒")
return
@@ -305,7 +288,8 @@
client := crm_aps.NewCrmAndApsGrpcServiceClient(grpc_init.CrmApsGrpcServiceConn)
projectList, err := client.GetApsProjectList(c, &crm_aps.GetApsProjectListRequest{})
if err != nil {
- ctx.FailWithMsg(ecode.UnknownErr, "grpc璋冪敤閿欒: "+err.Error())
+ logx.Errorf("grpc GetApsProjectList err: %v", err.Error())
+ ctx.FailWithMsg(ecode.UnknownErr, "鑾峰彇aps椤圭洰鍒楄〃澶辫触")
return
}
ctx.OkWithDetailed(projectList.List)
@@ -326,6 +310,15 @@
if !ok {
return
}
+ clientName := ""
+ if params.ClientId > 0 {
+ first, err := model.NewClientSearch(nil).SetId(params.ClientId).First()
+ if err != nil {
+ ctx.FailWithMsg(ecode.UnknownErr, "瀹㈡埛淇℃伅鏌ヨ澶辫触")
+ return
+ }
+ clientName = first.Name
+ }
m := make(map[string]interface{})
m["status"] = params.Status
m["project_id"] = params.ProjectId
@@ -343,17 +336,20 @@
p.Amount = product.Amount.String()
wmsProducts = append(wmsProducts, &p)
}
- clientWms := product_inventory.NewProductInventoryServiceClient(ProductInventoryServiceConn)
+ clientWms := product_inventory.NewProductInventoryServiceClient(grpc_init.ProductInventoryServiceConn)
_, err = clientWms.CreateOperation(ctx.GetCtx(), &product_inventory.CreateOperationRequest{
Number: params.Number,
Addressee: params.Addressee,
Address: params.Address,
Phone: params.Phone,
DeliverType: int32(params.DeliverType),
+ Source: "CRM",
+ ClientId: int64(params.ClientId),
+ ClientName: clientName,
ProductList: wmsProducts,
})
if err != nil {
- logx.Errorf("CreateOperation err: %v", err.Error())
+ logx.Errorf("grpc CreateOperation err: %v", err.Error())
}
//鎺ㄩ�佸埌aps
@@ -383,7 +379,8 @@
//鐘舵�佽繕鍘�
m["status"] = constvar.WaitConfirmed
_ = model.NewSalesDetailsSearch().SetNumber(params.Number).UpdateByMap(m)
- ctx.FailWithMsg(ecode.UnknownErr, "grpc璋冪敤閿欒: "+err.Error())
+ logx.Errorf("grpc SendSalesDetailsToApsProject err: %v", err.Error())
+ ctx.FailWithMsg(ecode.UnknownErr, "鎺ㄩ�佸け璐�,璇锋鏌ュ弬鏁版槸鍚︽纭�")
return
}
ctx.Ok()
--
Gitblit v1.8.0