使用angular5和Java按日期搜索数据

时间:2018-12-10 14:27:07

标签: java elasticsearch angular5 jhipster

我的UI在Angular5中,后端在Java Spring Boot中。我想创建弹性搜索。有照片 enter image description here

我的pagebale问题, 我要做的是,当单击按钮时,就会调用loadAll()方法。

我发送的名称为dateOt(起始日期)和dateDo(起始日期)的日期

loadAll() {
    this.kassaService.query({
        page: this.page - 1,
        size: this.itemsPerPage,
        sort: this.sort(),

        dateOt: this.dataEnterOt,
        dateDo: this.dataEnterDo,
    }).subscribe(
        (res: HttpResponse<Kassa[]>) => this.onSuccess(res.body, res.headers),
        (res: HttpErrorResponse) => this.onError(res.message)
    );
}

共有TotalItems:57000 当发送日期时,数据返回我的数据,而我需要此间隔中的数据。应该减少totalItems的数量,但是对于我来说,我现在使用的是X-Total-Count,它使我得到57000

令人满意的结果:

enter image description here

有一些代码:

  private onSuccess(data, headers) { 
    this.links = this.parseLinks.parse(headers.get('link'));
    this.totalItems = headers.get('X-Total-Count');
    this.queryCount = this.totalItems;
    this.kassas = data;
}

存储库:

 public ResponseEntity<List<KassaDTO>> getKassas(Pageable pageable, String dateOt, String dateDo) {

    Page<KassaDTO> page = kassaService.getKassa(pageable, dateOt, dateDo);

    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/kassas");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);

}

getKassa():

公共页面getKassa(可分页可分页,字符串dateOt,字符串dateDo){

    if (dateOt.equals("1") || dateDo.equals("1")) {
        dateOt = "2018-01-01";
        dateDo = "2100-01-01";
    }


    List<Object[]> kassaList = kassaRepository.findByDate(dateOt, dateDo, pageable.getOffset(), pageable.getPageSize());

    BigInteger sizeS = kassaRepository.getPage();

    List<KassaDTO> dtoList = new ArrayList<>();

    for (Object[] b : kassaList) {

        KassaDTO dto = new KassaDTO();
        String name_db = String.valueOf(b[7]);
        String name_cr = String.valueOf(b[10]);
        String purpose = String.valueOf(b[14]);
        name_db = name_db.replace("&quot;", "");
        name_cr = name_cr.replace("&quot;", "");
        purpose = purpose.replace("&quot;", "");
        purpose = purpose.replace("¬", "");
        name_db = name_db.replace("````", "'");


        dto.setId(b[0] != null ? Long.valueOf(b[0].toString()) : null);
        ////
        dto.setDate_enter(b[1] != null ? (b[1].toString()) : null);
        dto.setDate_prov(b[2] != null ? b[2].toString() : null);
        dto.setDate_doc(b[3] != null ? (b[3].toString()) : null);
        ///
        dto.setNum_doc(b[4] != null ? Long.valueOf(b[4].toString()) : null);
        dto.setAcc_db(b[5] != null ? b[5].toString() : null);
        dto.setBank_db(b[6] != null ? Long.valueOf(b[6].toString()) : null);
        dto.setName_db(b[7] != null ? name_db : null);
        dto.setAcc_cr(b[8] != null ? (b[8].toString()) : null);
        dto.setBank_cr(b[9] != null ? Long.valueOf(b[9].toString()) : null);
        dto.setName_cr(b[10] != null ? name_cr : null);
        dto.setCurrency(b[11] != null ? (String) b[11] : null);
        dto.setSumma(b[12] != null ? (String) b[12] : null);
        dto.setSumma_eq(b[13] != null ? (String) b[13] : null);
        dto.setPurpose(b[14] != null ? purpose : null);
        dto.setInn_db(b[15] != null ? Long.valueOf(b[15].toString()) : null);
        dto.setInn_cr(b[16] != null ? Long.valueOf(b[16].toString()) : null);
        dto.setLast_update(b[17] != null ? LocalDate.parse(b[17].toString()) : null);
        dto.setStatus(b[18] != null ? Integer.valueOf(b[18].toString()) : null);
        dto.setSys_id(b[19] != null ? String.valueOf(b[19]) : null);

        dtoList.add(dto);
    }

    Page<KassaDTO> dtoPage = new PageImpl<KassaDTO>(dtoList, pageable, sizeS.longValue());

    return dtoPage;
}

公共静态HttpHeaders generatePaginationHttpHeaders(页面页面,字符串baseUrl){

    HttpHeaders headers = new HttpHeaders();
    headers.add("X-Total-Count", Long.toString(page.getTotalElements()));
    String link = "";
    if ((page.getNumber() + 1) < page.getTotalPages()) {
        link = "<" + generateUri(baseUrl, page.getNumber() + 1, page.getSize()) + ">; rel=\"next\",";
    }
    // prev link
    if ((page.getNumber()) > 0) {
        link += "<" + generateUri(baseUrl, page.getNumber() - 1, page.getSize()) + ">; rel=\"prev\",";
    }
    // last and first link
    int lastPage = 0;
    if (page.getTotalPages() > 0) {
        lastPage = page.getTotalPages() - 1;
    }
    link += "<" + generateUri(baseUrl, lastPage, page.getSize()) + ">; rel=\"last\",";
    link += "<" + generateUri(baseUrl, 0, page.getSize()) + ">; rel=\"first\"";
    headers.add(HttpHeaders.LINK, link);
    return headers;
}

0 个答案:

没有答案