| | |
| | | response.FailWithMessage("保存失败", c) |
| | | return |
| | | } |
| | | err = server.SavePurchaseQualityInspection(list) |
| | | _, err = server.SavePurchaseQualityInspection(list) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("保存失败!", zap.Error(err)) |
| | | response.FailWithMessage("保存失败", c) |
| | |
| | | } |
| | | response.OkWithMessage("质检成功", c) |
| | | } |
| | | |
| | | // AllProductInWarehouse |
| | | // @Tags Purchase |
| | | // @Summary 全部合格入库 |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Param data body purchaserequest.SaveQualityInspectionInfo true "参数" |
| | | // @Success 200 {object} response.Response{data=[]purchase.PurchaseProductConfirm} "获取确认信息" |
| | | // @Router /purchase/allProductInWarehouse [post] |
| | | func (e *PurchaseApi) AllProductInWarehouse(c *gin.Context) { |
| | | var params []*purchaserequest.PurchaseProductConfirmInfo |
| | | err := c.ShouldBindJSON(¶ms) |
| | | if err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | |
| | | list := make([]*purchase.PurchaseProductConfirm, 0, len(params)) |
| | | if err := utils.AssignTo(params, &list); err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | |
| | | server := service.NewPurchaseService() |
| | | err = server.SavePurchaseProductConfirm(list) |
| | | |
| | | if err != nil { |
| | | global.GVA_LOG.Error("保存失败!", zap.Error(err)) |
| | | response.FailWithMessage("保存失败", c) |
| | | return |
| | | } |
| | | inspectionList, err := server.SavePurchaseQualityInspection(list) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("保存失败!", zap.Error(err)) |
| | | response.FailWithMessage("保存失败", c) |
| | | return |
| | | } |
| | | purchaseData, err := server.GetPurchaseByNumber(list[0].PurchaseNumber) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | return |
| | | } |
| | | product := make([]*purchase_wms.PurchaseProduct, 0) |
| | | ids := make([]int, 0) |
| | | for _, inspection := range inspectionList { |
| | | var p purchase_wms.PurchaseProduct |
| | | p.Id = inspection.ProductId |
| | | p.Amount = inspection.Amount.IntPart() |
| | | product = append(product, &p) |
| | | ids = append(ids, int(inspection.ID)) |
| | | } |
| | | client := purchase_wms.NewPurchaseServiceClient(purchase_wms.PurchaseConn) |
| | | _, err = client.PurchaseToWms(context.Background(), &purchase_wms.PurchaseToWmsRequest{ |
| | | Number: purchaseData.Number, |
| | | SupplierName: purchaseData.Supplier.Name, |
| | | SupplierId: int64(purchaseData.SupplierId), |
| | | Product: product, |
| | | Source: "SRM_PURCHASE", |
| | | WarehouseName: purchaseData.Warehouse, |
| | | }) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("grpc调用失败!", zap.Error(err)) |
| | | response.FailWithMessage("grpc调用失败", c) |
| | | return |
| | | } |
| | | err = server.UpdatePurchaseQualityInspection(ids, purchase.InWarehouse) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("质检失败!", zap.Error(err)) |
| | | response.FailWithMessage("质检失败", c) |
| | | return |
| | | } |
| | | response.OkWithMessage("质检成功", c) |
| | | } |