| | |
| | | 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/ecode" |
| | | "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) |
| | | if params.QuotationNumber != "" { |
| | | find, err := model.NewQuotationSearch(nil).SetNumber(params.QuotationNumber).Find() |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "报价单信息查询失败") |
| | | return |
| | | } |
| | | products := find.Products |
| | | ctx.OkWithDetailed(response.ListResponse{ |
| | | Data: products, |
| | | Count: int64(len(products)), |
| | | }) |
| | | return |
| | | } |
| | | cli := product.NewProductServiceClient(grpc_init.CrmApsGrpcServiceConn) |
| | | getProductListResponse, err := cli.GetProductList(ctx.GetCtx(), &product.GetProductListRequest{ |
| | | Page: cast.ToInt32(params.Page), |
| | | PageSize: cast.ToInt32(params.PageSize), |
| | | ProductNumber: params.ProductNumber, |
| | | ProductName: params.ProductName, |
| | | }) |
| | | if err != nil { |
| | | logx.Errorf("grpc GetProductList err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | if getProductListResponse.Code != 0 { |
| | | logx.Errorf("grpc GetProductList err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | rawProductList := getProductListResponse.List |
| | | productList := make([]model.Product, len(rawProductList)) |
| | | |
| | |
| | | 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) |
| | | productList[k].Unit = v.Unit |
| | | } |
| | | |
| | | if err != nil { |
| | | logx.Errorf("GetProductList err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | if getProductListResponse.Code != 0 { |
| | | logx.Errorf("GetProductList err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | ctx.OkWithDetailed(response.ListResponse{ |
| | | Data: productList, |
| | | Count: getProductListResponse.Total, |
| | |
| | | |
| | | // 获取产品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 { |
| | | logx.Errorf("GetProductInfo err: %v", err.Error()) |
| | | logx.Errorf(" grpc GetProductInfo err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | if getProductInfoResponse.Code != 0 { |
| | | logx.Errorf("GetProductInfo err: %v", err.Error()) |
| | | logx.Errorf("grpc GetProductInfo err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | |
| | | // @Summary 获取产品订单信息 |
| | | // @Produce application/json |
| | | // @Param number path string true "明细编码" |
| | | // @Success 200 {object} contextx.Response{data=[]product.WorkOrderInfo} "成功" |
| | | // @Success 200 {object} contextx.Response{data=response.Info} "成功" |
| | | // |
| | | // @Router /api/product/getProductOrderInfo/{number} [get] |
| | | func (ci *ProductApi) GetProductOrderInfo(c *gin.Context) { |
| | |
| | | return |
| | | } |
| | | number := c.Param("number") |
| | | first, err := model.NewSalesDetailsSearch().SetNumber(number).SetPreload(true).First() |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "明细详情查找失败") |
| | | if number == "" || number == "undefined" { |
| | | ctx.Ok() |
| | | return |
| | | } |
| | | params := make([]*product.Info, 0) |
| | | for _, p := range first.Products { |
| | | var pa product.Info |
| | | pa.ProductId = p.Number |
| | | pa.StartTime = utils.TimeToString(first.UpdatedAt) |
| | | pa.EndTime = first.DeliveryDate |
| | | params = append(params, &pa) |
| | | } |
| | | client := product.NewProductServiceClient(productServiceConn) |
| | | info, err := client.GetProductOrder(ctx.GetCtx(), &product.GetProductOrderRequest{Params: params}) |
| | | client := product.NewProductServiceClient(grpc_init.CrmApsGrpcServiceConn) |
| | | info, err := client.GetProductOrder(ctx.GetCtx(), &product.GetProductOrderRequest{SalesDetailsNumber: number}) |
| | | if err != nil { |
| | | logx.Errorf("GetProductOrder err: %v", err.Error()) |
| | | logx.Errorf("grpc GetProductOrder err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | ctx.OkWithDetailed(info.List) |
| | | var result response.Info |
| | | var list []response.WorkOrderInfo |
| | | for _, orderInfo := range info.List { |
| | | var wo response.WorkOrderInfo |
| | | wo.OrderId = orderInfo.OrderId |
| | | wo.ProductName = orderInfo.ProductName |
| | | wo.OrderStatus = orderInfo.OrderStatus |
| | | wo.WorkOrderId = orderInfo.WorkOrderId |
| | | wo.WorkOrderStatus = orderInfo.WorkOrderStatus |
| | | wo.StartTime = orderInfo.StartTime |
| | | wo.EndTime = orderInfo.EndTime |
| | | list = append(list, wo) |
| | | } |
| | | result.MakeInfo = list |
| | | var purchaseInfo []response.Purchase |
| | | for _, pl := range info.PurchaseList { |
| | | var p response.Purchase |
| | | p.Amount = pl.Amount |
| | | p.Status = pl.Status |
| | | p.PurchaseName = pl.PurchaseName |
| | | p.PurchaseNumber = pl.PurchaseNumber |
| | | p.SupplierName = pl.SupplierName |
| | | purchaseInfo = append(purchaseInfo, p) |
| | | } |
| | | result.PurchaseInfo = purchaseInfo |
| | | ctx.OkWithDetailed(result) |
| | | } |