Search in sources :

Example 16 with Pageable

use of org.springframework.data.domain.Pageable in project sic by belluccifranco.

the class NotaController method buscarNotasPorClienteYEmpresa.

@GetMapping("/notas/busqueda/criteria")
@ResponseStatus(HttpStatus.OK)
public Page<Nota> buscarNotasPorClienteYEmpresa(@RequestParam(value = "desde", required = false) Long desde, @RequestParam(value = "hasta", required = false) Long hasta, @RequestParam Long idCliente, @RequestParam Long idEmpresa, @RequestParam(required = false) Integer pagina, @RequestParam(required = false) Integer tamanio) {
    Calendar fechaDesde = Calendar.getInstance();
    Calendar fechaHasta = Calendar.getInstance();
    if (desde != null && hasta != null) {
        fechaDesde.setTimeInMillis(desde);
        fechaHasta.setTimeInMillis(hasta);
    }
    if (tamanio == null || tamanio <= 0) {
        tamanio = TAMANIO_PAGINA_DEFAULT;
    }
    if (pagina == null || pagina < 0) {
        pagina = 0;
    }
    Pageable pageable = new PageRequest(pagina, tamanio, new Sort(Sort.Direction.ASC, "fecha"));
    BusquedaNotaCriteria criteria = BusquedaNotaCriteria.builder().buscaPorFecha((desde != null) && (hasta != null)).fechaDesde(fechaDesde.getTime()).fechaHasta(fechaHasta.getTime()).empresa(empresaService.getEmpresaPorId(idEmpresa)).cantidadDeRegistros(0).cliente(clienteService.getClientePorId(idCliente)).pageable(pageable).build();
    return notaService.buscarNotasPorClienteYEmpresa(criteria);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Calendar(java.util.Calendar) Sort(org.springframework.data.domain.Sort) BusquedaNotaCriteria(sic.modelo.BusquedaNotaCriteria) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 17 with Pageable

use of org.springframework.data.domain.Pageable in project sic by belluccifranco.

the class CarritoCompraController method generarPedidoConItemsDelCarrito.

@PostMapping("/carrito-compra")
@ResponseStatus(HttpStatus.CREATED)
public Pedido generarPedidoConItemsDelCarrito(@RequestBody Pedido pedido) {
    Pageable pageable = new PageRequest(0, Integer.MAX_VALUE, new Sort(Sort.Direction.DESC, "idItemCarritoCompra"));
    List<ItemCarritoCompra> items = carritoCompraService.getAllItemsDelUsuario(pedido.getUsuario().getId_Usuario(), pageable).getContent();
    pedido.setRenglones(new ArrayList<>());
    items.forEach(i -> {
        pedido.getRenglones().add(new RenglonPedido(0, i.getProducto(), i.getCantidad(), 0, 0, i.getImporte()));
    });
    Pedido p = pedidoService.guardar(pedido);
    carritoCompraService.eliminarTodosLosItems(pedido.getUsuario().getId_Usuario());
    return p;
}
Also used : ItemCarritoCompra(sic.modelo.ItemCarritoCompra) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) RenglonPedido(sic.modelo.RenglonPedido) RenglonPedido(sic.modelo.RenglonPedido) Pedido(sic.modelo.Pedido) Sort(org.springframework.data.domain.Sort) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 18 with Pageable

use of org.springframework.data.domain.Pageable in project sic by belluccifranco.

the class FacturaController method buscarFacturaVenta.

@GetMapping("/facturas/venta/busqueda/criteria")
@ResponseStatus(HttpStatus.OK)
public Page<FacturaVenta> buscarFacturaVenta(@RequestParam Long idEmpresa, @RequestParam(required = false) Long desde, @RequestParam(required = false) Long hasta, @RequestParam(required = false) Long idCliente, @RequestParam(required = false) Integer nroSerie, @RequestParam(required = false) Integer nroFactura, @RequestParam(required = false) Long idViajante, @RequestParam(required = false) TipoDeComprobante tipoDeComprobante, @RequestParam(required = false) Long idUsuario, @RequestParam(required = false) Long nroPedido, @RequestParam(required = false) Boolean soloImpagas, @RequestParam(required = false) Boolean soloPagas, @RequestParam(required = false) Integer pagina, @RequestParam(required = false) Integer tamanio) {
    Calendar fechaDesde = Calendar.getInstance();
    Calendar fechaHasta = Calendar.getInstance();
    if ((desde != null) && (hasta != null)) {
        fechaDesde.setTimeInMillis(desde);
        fechaHasta.setTimeInMillis(hasta);
    }
    soloImpagas = (soloImpagas == null) ? false : soloImpagas;
    soloPagas = (soloPagas == null) ? false : soloPagas;
    if ((soloImpagas == true) && (soloPagas == true)) {
        soloImpagas = false;
        soloPagas = false;
    }
    Cliente cliente = new Cliente();
    if (idCliente != null) {
        cliente = clienteService.getClientePorId(idCliente);
    }
    Usuario usuario = new Usuario();
    if (idUsuario != null) {
        usuario = usuarioService.getUsuarioPorId(idUsuario);
    }
    Usuario viajante = new Usuario();
    if (idViajante != null) {
        viajante = usuarioService.getUsuarioPorId(idViajante);
    }
    if (tamanio == null || tamanio <= 0) {
        tamanio = TAMANIO_PAGINA_DEFAULT;
    }
    if (pagina == null || pagina < 0) {
        pagina = 0;
    }
    Pageable pageable = new PageRequest(pagina, tamanio, new Sort(Sort.Direction.DESC, "fecha"));
    BusquedaFacturaVentaCriteria criteria = BusquedaFacturaVentaCriteria.builder().empresa(empresaService.getEmpresaPorId(idEmpresa)).buscaPorFecha((desde != null) && (hasta != null)).fechaDesde(fechaDesde.getTime()).fechaHasta(fechaHasta.getTime()).buscaCliente(idCliente != null).cliente(cliente).buscaUsuario(idUsuario != null).usuario(usuario).buscaViajante(idViajante != null).viajante(viajante).buscaPorNumeroFactura((nroSerie != null) && (nroFactura != null)).numSerie((nroSerie != null) ? nroSerie : 0).numFactura((nroFactura != null) ? nroFactura : 0).buscarPorPedido(nroPedido != null).nroPedido((nroPedido != null) ? nroPedido : 0).buscaPorTipoComprobante(tipoDeComprobante != null).tipoComprobante((tipoDeComprobante != null) ? tipoDeComprobante : null).buscaSoloImpagas(soloImpagas).buscaSoloPagadas(soloPagas).cantRegistros(0).pageable(pageable).build();
    return facturaService.buscarFacturaVenta(criteria);
}
Also used : BusquedaFacturaVentaCriteria(sic.modelo.BusquedaFacturaVentaCriteria) PageRequest(org.springframework.data.domain.PageRequest) Usuario(sic.modelo.Usuario) Pageable(org.springframework.data.domain.Pageable) Calendar(java.util.Calendar) Sort(org.springframework.data.domain.Sort) Cliente(sic.modelo.Cliente) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 19 with Pageable

use of org.springframework.data.domain.Pageable in project halo by ruibaby.

the class BaseController method getNewComments.

/**
 * 获取新评论
 *
 * @param session session
 */
protected void getNewComments(HttpSession session) {
    Sort sort = new Sort(Sort.Direction.DESC, "commentDate");
    Pageable pageable = new PageRequest(0, 999, sort);
    Page<Comment> comments = commentService.findAllComments(1, pageable);
    session.removeAttribute("newComments");
    session.setAttribute("newComments", comments.getContent());
}
Also used : Comment(cc.ryanc.halo.model.domain.Comment) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort)

Example 20 with Pageable

use of org.springframework.data.domain.Pageable in project halo by ruibaby.

the class IndexController method ajaxIndex.

/**
 * ajax分页
 *
 * @param page page
 * @return list
 */
@GetMapping(value = "next")
@ResponseBody
public List<Post> ajaxIndex(@PathParam(value = "page") Integer page) {
    Sort sort = new Sort(Sort.Direction.DESC, "postDate");
    // 默认显示10条
    Integer size = 10;
    // 尝试加载设置选项,用于设置显示条数
    if (!StringUtils.isBlank(HaloConst.OPTIONS.get("index_posts"))) {
        size = Integer.parseInt(HaloConst.OPTIONS.get("index_posts"));
    }
    // 文章数据,只获取文章,没有分页
    Pageable pageable = new PageRequest(page - 1, size, sort);
    List<Post> posts = postService.findPostByStatus(0, pageable).getContent();
    return posts;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort)

Aggregations

Pageable (org.springframework.data.domain.Pageable)185 PageRequest (org.springframework.data.domain.PageRequest)88 Sort (org.springframework.data.domain.Sort)81 Test (org.junit.Test)39 PageImpl (org.springframework.data.domain.PageImpl)28 ArrayList (java.util.ArrayList)18 Collectors (java.util.stream.Collectors)17 List (java.util.List)15 Page (org.springframework.data.domain.Page)15 Autowired (org.springframework.beans.factory.annotation.Autowired)14 GetMapping (org.springframework.web.bind.annotation.GetMapping)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Test (org.junit.jupiter.api.Test)11 UUID (java.util.UUID)10 ApiOperation (io.swagger.annotations.ApiOperation)9 Calendar (java.util.Calendar)9 java.util (java.util)8 Lists (com.google.common.collect.Lists)7 Map (java.util.Map)7 Transactional (org.springframework.transaction.annotation.Transactional)6