Commit 9ac46e3f authored by frank.xa.zhang's avatar frank.xa.zhang

add new api GetCustomsInvoiceDataForDisplay

parent 9b4b919b
package pwc.taxtech.atms.controller;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.dto.PagingDto;
import pwc.taxtech.atms.dto.PagingResultDto;
import pwc.taxtech.atms.dto.vatdto.CustomsInvoiceDto;
import pwc.taxtech.atms.dto.vatdto.CustomsInvoiceFilter;
import pwc.taxtech.atms.dto.vatdto.JsonCustomsInvoiceDto;
import pwc.taxtech.atms.vat.service.CustomsInvoiceService;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping(value = "api/v1/CustomsInvoice")
public class CustomsInvoiceController {
@Autowired
CustomsInvoiceService customsInvoiceService;
@RequestMapping(value = "GetCustomsInvoiceDataForDisplay", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public String getCustomsInvoiceDataForDisplay(@RequestParam int fromPeriod, @RequestParam int toPeriod, @RequestParam String criteria, @RequestParam String pagination) {
CustomsInvoiceFilter filter = new CustomsInvoiceFilter();
if (StringUtils.isNotBlank(criteria) && !"null".equals(criteria)) {
filter = JSONObject.parseObject(criteria, CustomsInvoiceFilter.class);
} else {
filter = null;
}
PagingDto paging = new PagingDto();
if (StringUtils.isNotBlank(pagination) && !"null".equals(pagination)) {
paging = JSONObject.parseObject(pagination, PagingDto.class);
} else {
paging = null;
}
return convertCustomsInvoiceDataToJson(fromPeriod, toPeriod, filter, paging);
}
private String convertCustomsInvoiceDataToJson(int fromPeriod, int toPeriod, CustomsInvoiceFilter filter, PagingDto pagination) {
String result = StringUtils.EMPTY;
List<CustomsInvoiceDto> balanceList = customsInvoiceService.getCustomsInvoicesByPeriodIds(fromPeriod, toPeriod);
if (filter != null && !balanceList.isEmpty()) {
balanceList = filterCustomsInvoiceDataList(filter, balanceList);
}
if (pagination != null) {
int pageAskingFor = 0;
if (pagination.getPageIndex() > 0) {
pageAskingFor = pagination.getPageIndex() - 1;
}
pagination.setTotalCount(balanceList.size());
balanceList = balanceList.stream().skip(pageAskingFor * pagination.getPageSize()).limit(pagination.getPageSize()).collect(Collectors.toList());
}
List<JsonCustomsInvoiceDto> recordList = new ArrayList<>();
JsonCustomsInvoiceDto record;
int indexNumber = 1;
for (CustomsInvoiceDto dto : balanceList) {
record = new JsonCustomsInvoiceDto();
CommonUtils.copyProperties(dto, record);
record.setRecordNumber(String.valueOf(indexNumber));
record.setIssueDate(DateFormat.getDateInstance().format(dto.getIssueDate()));
record.setInvoiceTaxAmount(dto.getInvoiceTaxAmount() != null ? dto.getInvoiceTaxAmount().toString() : "0.00");
record.setInvoiceAmount(dto.getInvoiceAmount() != null ? dto.getInvoiceAmount().toString() : "0.00");
recordList.add(record);
indexNumber++;
}
PagingResultDto<JsonCustomsInvoiceDto> listWithPaging = new PagingResultDto<>();
listWithPaging.setPageInfo(pagination);
listWithPaging.setList(recordList);
result = JSONObject.toJSONString(listWithPaging);
return result;
}
private List<CustomsInvoiceDto> filterCustomsInvoiceDataList(CustomsInvoiceFilter filter, List<CustomsInvoiceDto> balanceList) {
if (!balanceList.isEmpty()) {
if (StringUtils.isNotBlank(filter.getPayNum())) {
String[] names = filter.getPayNum().split(" ");
List<CustomsInvoiceDto> ds = new ArrayList<>();
for (String name : names) {
ds.addAll(balanceList.stream().filter(a -> a.getPayNum().contains(name)).collect(Collectors.toList()));
}
balanceList = ds;
}
}
if (filter.getTaxAmountFrom() != null || filter.getTaxAmountTo() != null) {
if (filter.getTaxAmountFrom() != null && filter.getTaxAmountTo() != null) {
balanceList = balanceList.stream()
.filter(a -> a.getInvoiceTaxAmount() != null
&& (filter.getTaxAmountFrom().compareTo(a.getInvoiceAmount()) < 1
&& filter.getTaxAmountTo().compareTo(a.getInvoiceAmount()) > -1))
.collect(Collectors.toList());
} else if (filter.getTaxAmountFrom() != null) {
balanceList = balanceList.stream()
.filter(a -> a.getInvoiceTaxAmount() != null
&& filter.getTaxAmountFrom().compareTo(a.getInvoiceAmount()) < 1)
.collect(Collectors.toList());
} else {
balanceList = balanceList.stream()
.filter(a -> a.getInvoiceTaxAmount() != null
&& filter.getTaxAmountTo().compareTo(a.getInvoiceAmount()) > -1)
.collect(Collectors.toList());
}
}
if (filter.getInvoiceAmountFrom() != null || filter.getInvoiceAmountTo() != null) {
if (filter.getInvoiceAmountFrom() != null && filter.getInvoiceAmountTo() != null) {
balanceList = balanceList.stream()
.filter(a -> a.getInvoiceAmount() != null
&& (filter.getInvoiceAmountFrom().compareTo(a.getInvoiceAmount()) < 1
&& filter.getInvoiceAmountTo().compareTo(a.getInvoiceAmount()) > -1))
.collect(Collectors.toList());
} else if (filter.getInvoiceAmountFrom() != null) {
balanceList = balanceList.stream()
.filter(a -> a.getInvoiceAmount() != null
&& filter.getInvoiceAmountFrom().compareTo(a.getInvoiceAmount()) < 1)
.collect(Collectors.toList());
} else {
balanceList = balanceList.stream()
.filter(a -> a.getInvoiceAmount() != null
&& filter.getInvoiceAmountTo().compareTo(a.getInvoiceAmount()) > -1)
.collect(Collectors.toList());
}
}
if (filter.getInvoiceStartDate() != null || filter.getInvoiceEndDate() != null) {
if (filter.getInvoiceStartDate() != null && filter.getInvoiceEndDate() != null) {
balanceList = balanceList.stream()
.filter(a -> a.getIssueDate() != null
&& (filter.getInvoiceStartDate().compareTo(a.getIssueDate()) < 1
&& filter.getInvoiceEndDate().compareTo(a.getIssueDate()) > -1))
.collect(Collectors.toList());
} else if (filter.getInvoiceStartDate() != null) {
balanceList = balanceList.stream()
.filter(a -> a.getIssueDate() != null
&& filter.getInvoiceStartDate().compareTo(a.getIssueDate()) < 1)
.collect(Collectors.toList());
} else {
balanceList = balanceList.stream()
.filter(a -> a.getIssueDate() != null
&& filter.getInvoiceEndDate().compareTo(a.getIssueDate()) > -1)
.collect(Collectors.toList());
}
}
return balanceList;
}
}
package pwc.taxtech.atms.dto;
public class PagingDto {
import com.alibaba.fastjson.annotation.JSONField;
public class PagingDto {
@JSONField(name="TotalCount")
private Integer totalCount;
@JSONField(name="PageIndex")
private Integer pageIndex;
@JSONField(name="PageSize")
private Integer pageSize;
public Integer getTotalCount() {
......
package pwc.taxtech.atms.dto;
import com.alibaba.fastjson.annotation.JSONField;
import java.util.List;
public class PagingResultDto<T> {
@JSONField(name="List")
private List<T> list;
@JSONField(name="PageInfo")
private PagingDto pageInfo;
private T calculateData;
......
package pwc.taxtech.atms.dto.vatdto;
import java.math.BigDecimal;
import java.util.Date;
public class CustomsInvoiceDto {
private String customsId;
private String payNum;
private Date issueDate;
private BigDecimal invoiceTaxAmount;
private BigDecimal invoiceAmount;
private String auditResult;
private Date createTime;
private String creatorID;
private Integer periodId;
private String dataSourceId;
//数据源名称
private String dataSourceName;
private int seqNo;
public String getCustomsId() {
return customsId;
}
public void setCustomsId(String customsId) {
this.customsId = customsId;
}
public String getPayNum() {
return payNum;
}
public void setPayNum(String payNum) {
this.payNum = payNum;
}
public Date getIssueDate() {
return issueDate;
}
public void setIssueDate(Date issueDate) {
this.issueDate = issueDate;
}
public BigDecimal getInvoiceTaxAmount() {
return invoiceTaxAmount;
}
public void setInvoiceTaxAmount(BigDecimal invoiceTaxAmount) {
this.invoiceTaxAmount = invoiceTaxAmount;
}
public BigDecimal getInvoiceAmount() {
return invoiceAmount;
}
public void setInvoiceAmount(BigDecimal invoiceAmount) {
this.invoiceAmount = invoiceAmount;
}
public String getAuditResult() {
return auditResult;
}
public void setAuditResult(String auditResult) {
this.auditResult = auditResult;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getCreatorID() {
return creatorID;
}
public void setCreatorID(String creatorID) {
this.creatorID = creatorID;
}
public Integer getPeriodId() {
return periodId;
}
public void setPeriodId(Integer periodId) {
this.periodId = periodId;
}
public String getDataSourceId() {
return dataSourceId;
}
public void setDataSourceId(String dataSourceId) {
this.dataSourceId = dataSourceId;
}
public String getDataSourceName() {
return dataSourceName;
}
public void setDataSourceName(String dataSourceName) {
this.dataSourceName = dataSourceName;
}
public int getSeqNo() {
return seqNo;
}
public void setSeqNo(int seqNo) {
this.seqNo = seqNo;
}
}
package pwc.taxtech.atms.dto.vatdto;
import java.math.BigDecimal;
import java.util.Date;
public class CustomsInvoiceFilter {
private Integer periodFrom ;
private Integer periodTo ;
private Date invoiceStartDate ;
private Date invoiceEndDate ;
private String payNum ;
private BigDecimal taxAmountFrom ;
private BigDecimal taxAmountTo ;
private BigDecimal invoiceAmountFrom ;
private BigDecimal invoiceAmountTo ;
public Integer getPeriodFrom() {
return periodFrom;
}
public void setPeriodFrom(Integer periodFrom) {
this.periodFrom = periodFrom;
}
public Integer getPeriodTo() {
return periodTo;
}
public void setPeriodTo(Integer periodTo) {
this.periodTo = periodTo;
}
public Date getInvoiceStartDate() {
return invoiceStartDate;
}
public void setInvoiceStartDate(Date invoiceStartDate) {
this.invoiceStartDate = invoiceStartDate;
}
public Date getInvoiceEndDate() {
return invoiceEndDate;
}
public void setInvoiceEndDate(Date invoiceEndDate) {
this.invoiceEndDate = invoiceEndDate;
}
public String getPayNum() {
return payNum;
}
public void setPayNum(String payNum) {
this.payNum = payNum;
}
public BigDecimal getTaxAmountFrom() {
return taxAmountFrom;
}
public void setTaxAmountFrom(BigDecimal taxAmountFrom) {
this.taxAmountFrom = taxAmountFrom;
}
public BigDecimal getTaxAmountTo() {
return taxAmountTo;
}
public void setTaxAmountTo(BigDecimal taxAmountTo) {
this.taxAmountTo = taxAmountTo;
}
public BigDecimal getInvoiceAmountFrom() {
return invoiceAmountFrom;
}
public void setInvoiceAmountFrom(BigDecimal invoiceAmountFrom) {
this.invoiceAmountFrom = invoiceAmountFrom;
}
public BigDecimal getInvoiceAmountTo() {
return invoiceAmountTo;
}
public void setInvoiceAmountTo(BigDecimal invoiceAmountTo) {
this.invoiceAmountTo = invoiceAmountTo;
}
}
package pwc.taxtech.atms.dto.vatdto;
import java.util.Date;
public class JsonCustomsInvoiceDto {
private String recordNumber;
private String customsId;
private String payNum;
private String issueDate;
private String invoiceTaxAmount;
private String invoiceAmount;
private String auditResult;
private Date createTime;
private String creatorID;
private Integer periodId;
public String getCustomsId() {
return customsId;
}
public void setCustomsId(String customsId) {
this.customsId = customsId;
}
public String getPayNum() {
return payNum;
}
public void setPayNum(String payNum) {
this.payNum = payNum;
}
public String getIssueDate() {
return issueDate;
}
public void setIssueDate(String issueDate) {
this.issueDate = issueDate;
}
public String getInvoiceTaxAmount() {
return invoiceTaxAmount;
}
public void setInvoiceTaxAmount(String invoiceTaxAmount) {
this.invoiceTaxAmount = invoiceTaxAmount;
}
public String getInvoiceAmount() {
return invoiceAmount;
}
public void setInvoiceAmount(String invoiceAmount) {
this.invoiceAmount = invoiceAmount;
}
public String getAuditResult() {
return auditResult;
}
public void setAuditResult(String auditResult) {
this.auditResult = auditResult;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getCreatorID() {
return creatorID;
}
public void setCreatorID(String creatorID) {
this.creatorID = creatorID;
}
public Integer getPeriodId() {
return periodId;
}
public void setPeriodId(Integer periodId) {
this.periodId = periodId;
}
public String getRecordNumber() {
return recordNumber;
}
public void setRecordNumber(String recordNumber) {
this.recordNumber = recordNumber;
}
}
package pwc.taxtech.atms.vat.service;
import pwc.taxtech.atms.dto.vatdto.CustomsInvoiceDto;
import java.util.List;
public interface CustomsInvoiceService {
/**
*
* @param fromPeriod
* @param toPeriod
* @return
*/
List<CustomsInvoiceDto> getCustomsInvoicesByPeriodIds(int fromPeriod, int toPeriod);
}
package pwc.taxtech.atms.vat.service.impl;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.dto.vatdto.CustomsInvoiceDto;
import pwc.taxtech.atms.vat.entity.CustomsInvoiceExample;
import pwc.taxtech.atms.vat.service.CustomsInvoiceService;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
@Service
public class CustomsInvoiceServiceImpl extends VatAbstractService implements CustomsInvoiceService {
@Override
public List<CustomsInvoiceDto> getCustomsInvoicesByPeriodIds(int fromPeriod, int toPeriod) {
CustomsInvoiceExample example = new CustomsInvoiceExample();
example.setOrderByClause(" PayNum");
example.createCriteria().andPeriodIdBetween(fromPeriod, toPeriod);
List<CustomsInvoiceDto> result = new ArrayList<>();
customsInvoiceMapper.selectByExample(example).forEach(a -> {
CustomsInvoiceDto dto = new CustomsInvoiceDto();
CommonUtils.copyProperties(a, dto);
result.add(dto);
});
int seqNo = 1;
DecimalFormat df = new DecimalFormat("#.00");
for (CustomsInvoiceDto dto : result) {
dto.setSeqNo(seqNo++);
if (dto.getInvoiceAmount() != null) {
dto.setInvoiceAmount(new BigDecimal(df.format(dto.getInvoiceAmount())));
}
if (dto.getInvoiceTaxAmount() != null) {
dto.setInvoiceTaxAmount(new BigDecimal(df.format(dto.getInvoiceTaxAmount())));
}
}
return result;
}
}
......@@ -18,5 +18,7 @@ public class VatAbstractService {
InputVATInvoiceMapper inputVATInvoiceMapper;
@Autowired
OutputVATInvoiceMapper outputVATInvoiceMapper;
@Autowired
CustomsInvoiceMapper customsInvoiceMapper;
}
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