| | |
| | | package v1 |
| | | |
| | | import ( |
| | | "aps_crm/conf" |
| | | "aps_crm/model" |
| | | "aps_crm/model/grpc_init" |
| | | "aps_crm/model/request" |
| | | "aps_crm/model/response" |
| | | "aps_crm/pkg/contextx" |
| | |
| | | "aps_crm/pkg/logx" |
| | | "aps_crm/proto/product" |
| | | "aps_crm/utils" |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/shopspring/decimal" |
| | | "github.com/spf13/cast" |
| | | "google.golang.org/grpc" |
| | | "google.golang.org/grpc/credentials/insecure" |
| | | ) |
| | | |
| | | type ProductApi struct{} |
| | | |
| | | var ( |
| | | productServiceConn *grpc.ClientConn |
| | | ) |
| | | |
| | | func InitProductServiceConn() { |
| | | fmt.Println(conf.Conf.GrpcServiceAddr.Aps) |
| | | var err error |
| | | productServiceConn, 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 CloseProductServiceConn() { |
| | | if productServiceConn != nil { |
| | | productServiceConn.Close() |
| | | } |
| | | } |
| | | //var ( |
| | | // productServiceConn *grpc.ClientConn |
| | | //) |
| | | // |
| | | //func InitProductServiceConn() { |
| | | // var err error |
| | | // productServiceConn, 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 CloseProductServiceConn() { |
| | | // if productServiceConn != nil { |
| | | // productServiceConn.Close() |
| | | // } |
| | | //} |
| | | |
| | | // List |
| | | // |
| | |
| | | return |
| | | } |
| | | |
| | | cli := product.NewProductServiceClient(productServiceConn) |
| | | cli := product.NewProductServiceClient(grpc_init.CrmApsGrpcServiceConn) |
| | | getProductListResponse, err := cli.GetProductList(ctx.GetCtx(), &product.GetProductListRequest{ |
| | | Page: cast.ToInt32(params.Page), |
| | | PageSize: cast.ToInt32(params.PageSize), |
| | |
| | | |
| | | // 获取产品ID |
| | | productId := c.Query("productNumber") |
| | | cli := product.NewProductServiceClient(productServiceConn) |
| | | cli := product.NewProductServiceClient(grpc_init.CrmApsGrpcServiceConn) |
| | | |
| | | getProductInfoResponse, err := cli.GetProductInfo(ctx.GetCtx(), &product.GetProductInfoRequest{ProductId: productId}) |
| | | if err != nil { |
| | |
| | | pa.EndTime = first.DeliveryDate |
| | | params = append(params, &pa) |
| | | } |
| | | client := product.NewProductServiceClient(productServiceConn) |
| | | client := product.NewProductServiceClient(grpc_init.CrmApsGrpcServiceConn) |
| | | info, err := client.GetProductOrder(ctx.GetCtx(), &product.GetProductOrderRequest{Params: params}) |
| | | if err != nil { |
| | | logx.Errorf("GetProductOrder err: %v", err.Error()) |