From 2030ec81f18f4ec9ea1800f13046acafff6d50f7 Mon Sep 17 00:00:00 2001 From: yinbentan <yinbentan@live.com> Date: 星期四, 26 九月 2024 00:48:59 +0800 Subject: [PATCH] 添加grpc方法:客户信息维护 --- api/v1/code.go | 107 ++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 85 insertions(+), 22 deletions(-) diff --git a/api/v1/code.go b/api/v1/code.go index bb8ae8b..941623b 100644 --- a/api/v1/code.go +++ b/api/v1/code.go @@ -1,7 +1,9 @@ package v1 import ( - "aps_crm/conf" + "aps_crm/constvar" + "aps_crm/model" + "aps_crm/model/grpc_init" "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" @@ -10,30 +12,28 @@ "aps_crm/proto/code" "github.com/gin-gonic/gin" "github.com/spf13/cast" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" ) type CodeApi struct{} -var ( - codeServiceConn *grpc.ClientConn -) - -func InitCodeServiceConn() { - var err error - codeServiceConn, err = grpc.Dial(conf.Conf.GrpcServiceAddr.Aps, grpc.WithTransportCredentials(insecure.NewCredentials())) - if err != nil { - logx.Errorf("grpc dial product service error: %v", err.Error()) - return - } -} - -func CloseCodeServiceConn() { - if codeServiceConn != nil { - codeServiceConn.Close() - } -} +//var ( +// codeServiceConn *grpc.ClientConn +//) +// +//func InitCodeServiceConn() { +// var err error +// codeServiceConn, err = grpc.Dial(conf.Conf.GrpcServiceAddr.Aps, grpc.WithTransportCredentials(insecure.NewCredentials())) +// if err != nil { +// logx.Errorf("grpc dial product service error: %v", err.Error()) +// return +// } +//} +// +//func CloseCodeServiceConn() { +// if codeServiceConn != nil { +// codeServiceConn.Close() +// } +//} // GetCodeList // @@ -53,7 +53,7 @@ params.CodeStandID = c.Query("codeStandID") params.Name = c.Query("name") params.Type = c.Query("type") - client := code.NewCodeServiceClient(codeServiceConn) + client := code.NewCodeServiceClient(grpc_init.CrmApsGrpcServiceConn) list, err := client.GetCodeList(ctx.GetCtx(), &code.GetCodeListRequest{ Page: cast.ToInt32(params.Page), PageSize: cast.ToInt32(params.PageSize), @@ -71,3 +71,66 @@ Count: list.Total, }) } + +// GetAutoCode +// +// @Tags 缂栫爜 +// @Summary 鑾峰彇鑷姩缂栫爜 +// @Produce application/json +// @Param object body code.CodeStandard true "鍙傛暟" +// @Success 200 {object} response.ListResponse +// +// @Router /api/code/getAutoCode [post] +func (ca *CodeApi) GetAutoCode(c *gin.Context) { + var params code.CodeStandard + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + var ( + id = 0 + err error + ) + switch constvar.CodeStandardType(params.Type) { + case constvar.CodeStandardTypeSaleKey: + id, err = model.NewSaleChanceSearch().MaxAutoIncr() + case constvar.CodeStandardTypeSaleLead: + id, err = model.NewSalesLeadsSearch(nil).MaxAutoIncr() + case constvar.CodeStandardTypeCustom: + id, err = model.NewClientSearch(nil).MaxAutoIncr() + case constvar.CodeStandardTypeFollowRecord: + id, err = model.NewFollowRecordSearch().MaxAutoIncr() + case constvar.CodeStandardTypeQuotation: + id, err = model.NewQuotationSearch(nil).MaxAutoIncr() + case constvar.CodeStandardTypeSaleTotalOrder: + id, err = model.NewMasterOrderSearch().MaxAutoIncr() + case constvar.CodeStandardTypeSaleSuborder: + id, err = model.NewSubOrderSearch(nil).MaxAutoIncr() + case constvar.CodeStandardTypeSaleDetail: + id, err = model.NewSalesDetailsSearch().MaxAutoIncr() + case constvar.CodeStandardTypeSaleReturnGoods: + id, err = model.NewSalesReturnSearch().MaxAutoIncr() + case constvar.CodeStandardTypeSaleRefund: + id, err = model.NewSalesRefundSearch().MaxAutoIncr() + case constvar.CodeStandardTypeContract: + id, err = model.NewContractSearch().MaxAutoIncr() + case constvar.CodeStandardTypeServerContract: + id, err = model.NewServiceContractSearch().MaxAutoIncr() + case constvar.CodeStandardTypeCustomServer: + id, err = model.NewServiceOrderSearch().MaxAutoIncr() + case constvar.CodeStandardTypeServerFollow: + id, err = model.NewServiceFollowupSearch().MaxAutoIncr() + case constvar.CodeStandardTypeSaleInvoice: + id, err = model.NewInvoiceSearch().MaxAutoIncr() + default: + ctx.FailWithMsg(ecode.UnknownErr, "缂栫爜瑙勫垯涓嶅瓨鍦�") + return + } + if err != nil { + logx.Errorf("GetAutoCode err: %v", err.Error()) + ctx.FailWithMsg(ecode.UnknownErr, "鑾峰彇鏈�澶у�煎け璐�") + return + } + autoCode := model.GetAutoCode(id, ¶ms) + ctx.OkWithDetailed(autoCode) +} -- Gitblit v1.8.0