zhangqian
2024-03-14 389dffb0b6218f05277b8755bb82b61b6a316528
proto/product_inventory/server.go
@@ -17,12 +17,14 @@
}
type ProductAndLocationInfo struct {
   ProductId     string          `json:"productId"`
   Amount        decimal.Decimal `json:"amount"`
   LocationId    int             `json:"locationId"`
   Number        string          `json:"number"`
   WaybillNumber string          `json:"waybillNumber"`
   Name          string          `json:"name"`
   ProductId      string          `json:"productId"`
   Amount         decimal.Decimal `json:"amount"`
   LocationId     int             `json:"locationId"`
   FromLocationId int             `json:"fromLocationId"`
   ToLocationId   int             `json:"toLocationId"`
   Number         string          `json:"number"`
   WaybillNumber  string          `json:"waybillNumber"`
   Name           string          `json:"name"`
}
func (s *Server) GetInventoryProductInfo(ctx context.Context, req *GetInventoryProductInfoRequest) (*GetInventoryProductInfoResponse, error) {
@@ -33,12 +35,19 @@
   var details []ProductAndLocationInfo
   var productIds []string
   resp := new(GetInventoryProductInfoResponse)
   err := models.NewOperationDetailsSearch().Orm.Model(&models.OperationDetails{}).
      Select("wms_operation_details.product_id,wms_operation_details.amount,wms_operation_details.from_location_id as location_id,"+
   search := models.NewOperationDetailsSearch().Orm.Model(&models.OperationDetails{}).
      Select("wms_operation_details.product_id,wms_operation_details.amount,wms_operation_details.from_location_id,wms_operation_details.to_location_id"+
         "wms_operation.number,wms_operation.waybill_number, logistic_company.name").
      Joins("left join wms_operation on wms_operation.id = wms_operation_details.operation_id").
      Joins("left join logistic_company on logistic_company.id = wms_operation.logistic_company_id").
      Where("wms_operation.source_number = ?", req.Number).Find(&details).Error
      Where("wms_operation.source_number = ?", req.Number)
   if req.IsInput {
      search.Where("wms_operation.base_operation_type = ?", constvar.BaseOperationTypeIncoming)
   }
   if req.IsOutput {
      search.Where("wms_operation.base_operation_type = ?", constvar.BaseOperationTypeOutgoing)
   }
   err := search.Find(&details).Error
   if err != nil {
      return nil, err
   }
@@ -49,8 +58,12 @@
   var locationId int
   for _, detail := range details {
      productIds = append(productIds, detail.ProductId)
      locationIds = append(locationIds, detail.LocationId)
      locationId = detail.LocationId
      if req.IsInput { //只查入库
         locationIds = append(locationIds, detail.ToLocationId)
      } else if req.IsOutput { //只查出库
         locationIds = append(locationIds, detail.FromLocationId)
      }
      locationId = detail.FromLocationId
   }
   //查询产品信息
   materials, err := models.NewMaterialSearch().SetIDs(productIds).FindNotTotal()