Commit 2a574d0b authored by neo's avatar neo

[dev] add mypage for invoice

parent 6ee2a5fd
......@@ -337,13 +337,6 @@
<artifactId>spring-data-commons</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>
<profiles>
......
package pwc.taxtech.atms.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -10,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import pwc.taxtech.atms.dto.PagingResultDto;
import pwc.taxtech.atms.dto.vatdto.ImportInputInvoiceDto;
import pwc.taxtech.atms.dto.vatdto.ImportInputInvoiceItemDto;
import pwc.taxtech.atms.dto.vatdto.InputInvoice;
......@@ -29,7 +29,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
import static javax.servlet.http.HttpServletResponse.SC_OK;
......@@ -44,10 +43,8 @@ public class InputInvoiceImportController {
@RequestMapping(value = "inputInvoicePreviewList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody
Page<InputInvoice> getInputInvoiceTreeViewData(@RequestBody InputInvoicePreviewQueryParam paras) {
Page<InputInvoice> result = inputInvoiceDataImportService.getInputInvoiceTreeViewData(paras);
if (result == null) return Page.empty();
return result;
PagingResultDto<InputInvoice> getInputInvoiceTreeViewData(@RequestBody InputInvoicePreviewQueryParam paras) {
return inputInvoiceDataImportService.getInputInvoiceTreeViewData(paras);
}
@RequestMapping(value = "exportQueryData/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
......@@ -83,7 +80,7 @@ public class InputInvoiceImportController {
}
private int getDownloadFilePath(InputInvoicePreviewQueryParam paras, OutputStream outputStream) {
List<InputInvoice> list = inputInvoiceDataImportService.getInputInvoiceTreeViewData(paras).get().collect(Collectors.toList());
List<InputInvoice> list = inputInvoiceDataImportService.getInputInvoiceTreeViewData(paras).getList();
if (list.size() == 0) {
return 0;
}
......
......@@ -2,7 +2,6 @@ package pwc.taxtech.atms.vat.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.google.gson.Gson;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
......@@ -12,13 +11,12 @@ import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.constant.enums.EnumTbImportType;
import pwc.taxtech.atms.constant.enums.EnumValidationType;
import pwc.taxtech.atms.dto.FieldsMapper;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.PagingResultDto;
import pwc.taxtech.atms.dto.vatdto.InputInvoice;
import pwc.taxtech.atms.dto.vatdto.InputVATInvoiceDto;
import pwc.taxtech.atms.dto.vatdto.RestResponsePage;
......@@ -44,18 +42,18 @@ public class InputInvoiceDataImportServiceImpl extends VatAbstractService {
@Autowired
private SqlSessionTemplate dynamicSqlSessionTemplate;
public Page<InputInvoice> getInputInvoiceTreeViewData(InputInvoicePreviewQueryParam paras) {
public PagingResultDto<InputInvoice> getInputInvoiceTreeViewData(InputInvoicePreviewQueryParam paras) {
return get(paras.getInvoiceCode(), paras.getPeriodStart(), paras.getPageInfo().getPageIndex(), paras.getPageInfo().getPageSize());
}
private Page<InputInvoice> get(String code, int period, int page, int size) {
RestResponsePage<InputInvoice> pageInput = null;
private PagingResultDto<InputInvoice> get(String code, int period, int page, int size) {
PagingResultDto<InputInvoice> pageInput = null;
try (CloseableHttpClient httpclient = HttpClients.createDefault();) {
HttpGet httpget = new HttpGet("http://localhost:8089/input_invoices?page=" + page + "&size=" + size
+ "&code=" + code + "&period=" + period);
try (CloseableHttpResponse response = httpclient.execute(httpget)) {
String inputStr = EntityUtils.toString(response.getEntity());
pageInput = JSONObject.parseObject(inputStr, new TypeReference<RestResponsePage<InputInvoice>>() {
pageInput = JSONObject.parseObject(inputStr, new TypeReference<PagingResultDto<InputInvoice>>() {
}.getType());
}
} catch (IOException e) {
......
......@@ -77,6 +77,11 @@
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.40</version>
</dependency>
</dependencies>
<dependencyManagement>
......
package pwc.taxtech.invoice.common;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class PagingDto {
private Integer TotalCount;
private Integer PageIndex;
private Integer PageSize;
public PagingDto(Integer totalCount, Integer pageIndex, Integer pageSize) {
TotalCount = totalCount;
PageIndex = pageIndex;
PageSize = pageSize;
}
}
package pwc.taxtech.invoice.common;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter
@Setter
public class PagingResultDto<T> {
@JSONField(name = "List")
private List<T> list;
@JSONField(name = "PageInfo")
private PagingDto pageInfo;
private T calculateData;
}
......@@ -6,6 +6,8 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pwc.taxtech.invoice.common.PagingDto;
import pwc.taxtech.invoice.common.PagingResultDto;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
......@@ -16,8 +18,12 @@ public class InputInvoiceController {
InputInvoiceRepository repository;
@RequestMapping(method = GET)
public Page<InputInvoice> getAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "20") int size) {
if(page<0)page=0;
return repository.findAll(PageRequest.of(page-1, size));
public PagingResultDto<InputInvoice> getAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "20") int size) {
if (page < 0) page = 0;
Page<InputInvoice> pageResult = repository.findAll(PageRequest.of(page - 1, size));
PagingResultDto<InputInvoice> pageReturn = new PagingResultDto();
pageReturn.setList(pageResult.getContent());
pageReturn.setPageInfo(new PagingDto(pageResult.getTotalPages(), pageResult.getPageable().getPageNumber(), pageResult.getPageable().getPageSize()));
return pageReturn;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment