liujiandao
2023-09-22 dd07a07290bf66fde945dbbebc23ae048205775d
api/v1/test/product.go
@@ -5,6 +5,7 @@
   "github.com/spf13/cast"
   "go.uber.org/zap"
   "google.golang.org/grpc"
   "google.golang.org/grpc/credentials/insecure"
   "srm/global"
   "srm/model/common/request"
   "srm/model/common/response"
@@ -25,17 +26,17 @@
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body test.Product true "创建Product"
// @Param data body request.ProductCreate true "创建Product"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /p/createProduct [post]
func (pApi *ProductApi) CreateProduct(c *gin.Context) {
   var p test.Product
   var p testReq.ProductCreate
   err := c.ShouldBindJSON(&p)
   if err != nil {
      response.FailWithMessage(err.Error(), c)
      return
   }
   if err := pService.CreateProduct(&p); err != nil {
   if err := pService.CreateProduct(p.List); err != nil {
      global.GVA_LOG.Error("创建失败!", zap.Error(err))
      response.FailWithMessage("创建失败", c)
   } else {
@@ -172,14 +173,14 @@
   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 InitProductServiceConn() {
   var err error
   productServiceConn, err = grpc.Dial(global.GVA_CONFIG.System.GrpcUrl, grpc.WithTransportCredentials(insecure.NewCredentials()))
   if err != nil {
      //logx.Errorf("grpc dial product service error: %v", err.Error())
      return
   }
}
func CloseProductServiceConn() {
   if productServiceConn != nil {
@@ -218,24 +219,25 @@
      productList[k].Number = v.Number
      productList[k].Name = v.Name
      productList[k].Unit = v.Unit
      productList[k].PurchasePrice = &v.SalePrice
      //productList[k].MinimumStock = &v.SalePrice
      //productList[k].MaximumStock = &v.SalePrice
      //productList[k].Remark = &v.SalePrice
      productList[k].PurchasePrice = v.SalePrice
      min := int(v.MinInventory)
      productList[k].MinimumStock = min
      max := int(v.MaxInventory)
      productList[k].MaximumStock = max
      productList[k].Remark = v.Node
      productList[k].ProductType = v.MaterialMode
   }
   if err != nil || getProductListResponse.Code != 0 {
      global.GVA_LOG.Error("获取失败!", zap.Error(err))
      response.FailWithMessage("获取失败", c)
      return
   } else {
      response.OkWithDetailed(response.PageResult{
         List:     productList,
         Total:    int64(len(productList)),
         Page:     pageInfo.Page,
         PageSize: pageInfo.PageSize,
      }, "获取成功", c)
   }
   response.OkWithDetailed(response.PageResult{
      List:     productList,
      Total:    0,
      Page:     pageInfo.Page,
      PageSize: pageInfo.PageSize,
   }, "获取成功", c)
}