From 42ca2293072e5eb011e655c9cc8fd9bf0ba376f1 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期四, 23 十一月 2023 14:42:58 +0800 Subject: [PATCH] 推送销售明细信息到其他系统 --- api/v1/salesDetails.go | 90 +++++++++++++++++---------------------------- 1 files changed, 34 insertions(+), 56 deletions(-) diff --git a/api/v1/salesDetails.go b/api/v1/salesDetails.go index 625e2b6..c1ce33d 100644 --- a/api/v1/salesDetails.go +++ b/api/v1/salesDetails.go @@ -289,53 +289,6 @@ ctx.OkWithDetailed(list) } -// CreateOperation -// -// @Tags SalesDetails -// @Summary 鍒涘缓浜у搧鍑哄簱淇℃伅 -// @Produce application/json -// @Param object body request.SalesDetails true "鏌ヨ鍙傛暟" -// @Success 200 {object} response.ListResponse -// -// @Router /api/salesDetails/createOperation [post] -func (s *SalesDetailsApi) CreateOperation(c *gin.Context) { - var params request.SalesDetails - ctx, ok := contextx.NewContext(c, ¶ms) - if !ok { - return - } - m := make(map[string]interface{}) - m["status"] = params.Status - err := model.NewSalesDetailsSearch().SetNumber(params.Number).UpdateByMap(m) - if err != nil { - ctx.FailWithMsg(ecode.UnknownErr, "鐘舵�佹洿鏂板け璐�") - return - } - - client := product_inventory.NewProductInventoryServiceClient(ProductInventoryServiceConn) - products := make([]*product_inventory.InventoryProduct, 0) - for _, product := range params.Products { - var p product_inventory.InventoryProduct - p.Id = product.Number - p.Amount = product.Amount.String() - products = append(products, &p) - } - _, err = client.CreateOperation(ctx.GetCtx(), &product_inventory.CreateOperationRequest{ - Number: params.Number, - Addressee: params.Addressee, - Address: params.Address, - Phone: params.Phone, - DeliverType: int32(params.DeliverType), - ProductList: products, - }) - if err != nil { - logx.Errorf("CreateOperation err: %v", err.Error()) - ctx.FailWithMsg(ecode.UnknownErr, "grpc璋冪敤閿欒") - return - } - ctx.Ok() -} - // GetApsProjectList // // @Tags SalesDetails @@ -358,16 +311,16 @@ ctx.OkWithDetailed(projectList.List) } -// SendSalesDetailsToApsProject +// SendSalesDetailsToOtherSystem // // @Tags SalesDetails -// @Summary 鎺ㄩ�侀攢鍞槑缁嗕俊鎭埌aps椤圭洰妯″潡 +// @Summary 鎺ㄩ�侀攢鍞槑缁嗕俊鎭埌鍏朵粬绯荤粺 // @Produce application/json // @Param object body request.SalesDetails true "鏌ヨ鍙傛暟" // @Success 200 {object} response.ListResponse // -// @Router /api/salesDetails/sendSalesDetailsToApsProject [post] -func (s *SalesDetailsApi) SendSalesDetailsToApsProject(c *gin.Context) { +// @Router /api/salesDetails/sendSalesDetailsToOtherSystem [post] +func (s *SalesDetailsApi) SendSalesDetailsToOtherSystem(c *gin.Context) { var params request.SalesDetails ctx, ok := contextx.NewContext(c, ¶ms) if !ok { @@ -381,18 +334,40 @@ return } - products := make([]*crm_aps.SalesDetailsProduct, 0) + //鎺ㄩ�佸埌wms + wmsProducts := make([]*product_inventory.InventoryProduct, 0) + for _, product := range params.Products { + var p product_inventory.InventoryProduct + p.Id = product.Number + p.Amount = product.Amount.String() + wmsProducts = append(wmsProducts, &p) + } + clientWms := product_inventory.NewProductInventoryServiceClient(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), + ProductList: wmsProducts, + }) + if err != nil { + logx.Errorf("CreateOperation err: %v", err.Error()) + } + + //鎺ㄩ�佸埌aps + ApsProducts := make([]*crm_aps.SalesDetailsProduct, 0) var total decimal.Decimal for _, product := range params.Products { var sp crm_aps.SalesDetailsProduct sp.ProductId = product.Number sp.Amount = product.Amount.IntPart() - products = append(products, &sp) + ApsProducts = append(ApsProducts, &sp) total = total.Add(product.Amount) } - client := crm_aps.NewCrmAndApsGrpcServiceClient(grpc_init.CrmApsGrpcServiceConn) - _, err = client.SendSalesDetailsToApsProject(c, &crm_aps.SendSalesDetailsToApsProjectRequest{ + clientAps := crm_aps.NewCrmAndApsGrpcServiceClient(grpc_init.CrmApsGrpcServiceConn) + _, err = clientAps.SendSalesDetailsToApsProject(c, &crm_aps.SendSalesDetailsToApsProjectRequest{ Number: params.Number, ClientName: params.Client.Name, MemberName: params.Member.Username, @@ -401,9 +376,12 @@ Source: params.Source, ProductTotal: total.IntPart(), ProjectId: params.ProjectId, - Products: products, + Products: ApsProducts, }) if err != nil { + //鐘舵�佽繕鍘� + m["status"] = constvar.WaitConfirmed + _ = model.NewSalesDetailsSearch().SetNumber(params.Number).UpdateByMap(m) ctx.FailWithMsg(ecode.UnknownErr, "grpc璋冪敤閿欒: "+err.Error()) return } -- Gitblit v1.8.0