| | |
| | | |
| | | import ( |
| | | "aps_crm/conf" |
| | | "aps_crm/model" |
| | | "aps_crm/model/request" |
| | | "aps_crm/model/response" |
| | | "aps_crm/pkg/contextx" |
| | |
| | | "aps_crm/proto/product" |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/shopspring/decimal" |
| | | "github.com/spf13/cast" |
| | | "google.golang.org/grpc" |
| | | "google.golang.org/grpc/credentials/insecure" |
| | |
| | | if err != nil { |
| | | logx.Errorf("grpc dial product service error: %v", err.Error()) |
| | | return |
| | | } |
| | | } |
| | | |
| | | func CloseProductServiceConn() { |
| | | if productServiceConn != nil { |
| | | productServiceConn.Close() |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | cli := product.NewProductServiceClient(productServiceConn) |
| | | |
| | | getProductListResponse, err := cli.GetProductList(ctx.GetCtx(), &product.GetProductListRequest{ |
| | | Page: cast.ToInt32(params.Page), |
| | | PageSize: cast.ToInt32(params.PageSize), |
| | | ProductNumber: params.ProductNumber, |
| | | ProductName: params.ProductName, |
| | | }) |
| | | rawProductList := getProductListResponse.List |
| | | productList := make([]model.Product, len(rawProductList)) |
| | | |
| | | for k, v := range rawProductList { |
| | | productList[k].Number = v.Number |
| | | productList[k].Name = v.Name |
| | | productList[k].Price = decimal.NewFromFloat(v.SalePrice).Round(2) |
| | | productList[k].Amount = decimal.NewFromFloat(1) |
| | | productList[k].Total = productList[k].Price.Mul(productList[k].Amount).Round(2) |
| | | } |
| | | |
| | | if err != nil { |
| | | logx.Errorf("GetProductList err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | |
| | | return |
| | | } |
| | | ctx.OkWithDetailed(response.ListResponse{ |
| | | Data: getProductListResponse.List, |
| | | Data: productList, |
| | | Count: getProductListResponse.Total, |
| | | }) |
| | | } |
| | |
| | | productId := c.Query("productNumber") |
| | | cli := product.NewProductServiceClient(productServiceConn) |
| | | |
| | | getProductInfoResponse, err := cli.GetProductInfo(ctx.GetCtx(), &product.GetProductInfoRequest{ProductId: productId}, nil) |
| | | getProductInfoResponse, err := cli.GetProductInfo(ctx.GetCtx(), &product.GetProductInfoRequest{ProductId: productId}) |
| | | if err != nil { |
| | | logx.Errorf("GetProductInfo err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | ctx.OkWithDetailed(contextx.Response{ |
| | | Data: getProductInfoResponse.Data, |
| | | }) |
| | | ctx.OkWithDetailed(getProductInfoResponse.Data) |
| | | } |