Commit 7b00befd authored by frank.xa.zhang's avatar frank.xa.zhang

add new api voucherSelectAdvancedByEntry

parent adedaf39
package pwc.taxtech.atms.controller;
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.RestController;
import pwc.taxtech.atms.constant.enums.VoucherSearchEnum;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.vatdto.QueryVoucherParmDto;
import pwc.taxtech.atms.vat.service.VoucherService;
@RequestMapping(value = "api/v1/voucher")
@RestController
public class VoucherController {
@Autowired
VoucherService voucherService;
@RequestMapping(value = "voucherSelectAdvancedByEntry", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public OperationResultDto<Object> voucherSelectAdvancedByEntry(QueryVoucherParmDto parmDto) {
return null;
public OperationResultDto<Object> voucherSelectAdvancedByEntry(QueryVoucherParmDto parmDto) throws Exception {
return voucherService.voucherSelectAdvancedByEntry(parmDto.getListQueryCondition(), VoucherSearchEnum.values()[parmDto.getMainRelation()], parmDto.isAllJe(), parmDto.getPagingInfo());
}
@RequestMapping(value = "voucherSelectAdvancedCount", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public OperationResultDto<Object> VoucherSelectAdvancedCount(QueryVoucherParmDto parmDto) {
return null;
public OperationResultDto<Object> voucherSelectAdvancedCount(QueryVoucherParmDto parmDto) throws Exception {
return voucherService.voucherSelectAdvancedCount(parmDto.getListQueryCondition(), VoucherSearchEnum.values()[parmDto.getMainRelation()], parmDto.isEntryShow(), parmDto.isAllJe());
}
}
package pwc.taxtech.atms.dto.vatdto;
import java.math.BigDecimal;
import java.util.List;
public class QueryVoucherDto {
private List<VoucherDto> voucherList;
//凭证总数
private int vidCount;
//分录总数
private int itemIDCount;
private BigDecimal debitSum;
private BigDecimal creditSum;
public List<VoucherDto> getVoucherList() {
return voucherList;
}
public void setVoucherList(List<VoucherDto> voucherList) {
this.voucherList = voucherList;
}
public int getVidCount() {
return vidCount;
}
public void setVidCount(int vidCount) {
this.vidCount = vidCount;
}
public int getItemIDCount() {
return itemIDCount;
}
public void setItemIDCount(int itemIDCount) {
this.itemIDCount = itemIDCount;
}
public BigDecimal getDebitSum() {
return debitSum;
}
public void setDebitSum(BigDecimal debitSum) {
this.debitSum = debitSum;
}
public BigDecimal getCreditSum() {
return creditSum;
}
public void setCreditSum(BigDecimal creditSum) {
this.creditSum = creditSum;
}
}
package pwc.taxtech.atms.dto.vatdto;
public class VIDCountDto {
private String vid;
private String group;
private Integer period;
public String getVid() {
return vid;
}
public void setVid(String vid) {
this.vid = vid;
}
public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = group;
}
public Integer getPeriod() {
return period;
}
public void setPeriod(Integer period) {
this.period = period;
}
public VIDCountDto(String vid, String group, Integer period) {
this.vid = vid;
this.group = group;
this.period = period;
}
}
package pwc.taxtech.atms.dto.vatdto;
import java.math.BigDecimal;
import java.util.Date;
public class VoucherDto {
private String voucherID;
private String vID;
private Date date;
//private String GroupNum ;
private String group;
private Integer period;
private String customerCode;
private String customerName;
private String summary;
private String acctCode;
private BigDecimal debit;
private BigDecimal credit;
private BigDecimal debitQty;
private BigDecimal creditQty;
private Long attach;
private Long itemID;
private Integer status;
private Date createdTime;
private Integer isManual;
private Integer manualUser;
private Date manualTime;
private String stdCode;
private String mappingReason;
private Integer mappingUser;
private Date mappingTime;
private String manualReason;
private String foreignCurrency;
private BigDecimal foreignDebit;
private BigDecimal foreignCredit;
private String checkedBy;
private String issuedBy;
private String bookedBy;
private String cashier;
/**
* 是否被凭证重分类过
*/
private Boolean isRecate;
private Integer originalPeriod;
private String acctCodeAndNameShow; //界面显示
private String customerCodeAndNameShow; //界面显示
private String stdCodeAndNameShow; //界面显示
private String groupShow; //界面显示
public String getVoucherID() {
return voucherID;
}
public void setVoucherID(String voucherID) {
this.voucherID = voucherID;
}
public String getvID() {
return vID;
}
public void setvID(String vID) {
this.vID = vID;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = group;
}
public Integer getPeriod() {
return period;
}
public void setPeriod(Integer period) {
this.period = period;
}
public String getCustomerCode() {
return customerCode;
}
public void setCustomerCode(String customerCode) {
this.customerCode = customerCode;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public String getAcctCode() {
return acctCode;
}
public void setAcctCode(String acctCode) {
this.acctCode = acctCode;
}
public BigDecimal getDebit() {
return debit;
}
public void setDebit(BigDecimal debit) {
this.debit = debit;
}
public BigDecimal getCredit() {
return credit;
}
public void setCredit(BigDecimal credit) {
this.credit = credit;
}
public BigDecimal getDebitQty() {
return debitQty;
}
public void setDebitQty(BigDecimal debitQty) {
this.debitQty = debitQty;
}
public BigDecimal getCreditQty() {
return creditQty;
}
public void setCreditQty(BigDecimal creditQty) {
this.creditQty = creditQty;
}
public Long getAttach() {
return attach;
}
public void setAttach(Long attach) {
this.attach = attach;
}
public Long getItemID() {
return itemID;
}
public void setItemID(Long itemID) {
this.itemID = itemID;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Date getCreatedTime() {
return createdTime;
}
public void setCreatedTime(Date createdTime) {
this.createdTime = createdTime;
}
public Integer getIsManual() {
return isManual;
}
public void setIsManual(Integer isManual) {
this.isManual = isManual;
}
public Integer getManualUser() {
return manualUser;
}
public void setManualUser(Integer manualUser) {
this.manualUser = manualUser;
}
public Date getManualTime() {
return manualTime;
}
public void setManualTime(Date manualTime) {
this.manualTime = manualTime;
}
public String getStdCode() {
return stdCode;
}
public void setStdCode(String stdCode) {
this.stdCode = stdCode;
}
public String getMappingReason() {
return mappingReason;
}
public void setMappingReason(String mappingReason) {
this.mappingReason = mappingReason;
}
public Integer getMappingUser() {
return mappingUser;
}
public void setMappingUser(Integer mappingUser) {
this.mappingUser = mappingUser;
}
public Date getMappingTime() {
return mappingTime;
}
public void setMappingTime(Date mappingTime) {
this.mappingTime = mappingTime;
}
public String getManualReason() {
return manualReason;
}
public void setManualReason(String manualReason) {
this.manualReason = manualReason;
}
public String getForeignCurrency() {
return foreignCurrency;
}
public void setForeignCurrency(String foreignCurrency) {
this.foreignCurrency = foreignCurrency;
}
public BigDecimal getForeignDebit() {
return foreignDebit;
}
public void setForeignDebit(BigDecimal foreignDebit) {
this.foreignDebit = foreignDebit;
}
public BigDecimal getForeignCredit() {
return foreignCredit;
}
public void setForeignCredit(BigDecimal foreignCredit) {
this.foreignCredit = foreignCredit;
}
public String getCheckedBy() {
return checkedBy;
}
public void setCheckedBy(String checkedBy) {
this.checkedBy = checkedBy;
}
public String getIssuedBy() {
return issuedBy;
}
public void setIssuedBy(String issuedBy) {
this.issuedBy = issuedBy;
}
public String getBookedBy() {
return bookedBy;
}
public void setBookedBy(String bookedBy) {
this.bookedBy = bookedBy;
}
public String getCashier() {
return cashier;
}
public void setCashier(String cashier) {
this.cashier = cashier;
}
public Boolean getRecate() {
return isRecate;
}
public void setRecate(Boolean recate) {
isRecate = recate;
}
public Integer getOriginalPeriod() {
return originalPeriod;
}
public void setOriginalPeriod(Integer originalPeriod) {
this.originalPeriod = originalPeriod;
}
public String getAcctCodeAndNameShow() {
return acctCodeAndNameShow;
}
public void setAcctCodeAndNameShow(String acctCodeAndNameShow) {
this.acctCodeAndNameShow = acctCodeAndNameShow;
}
public String getCustomerCodeAndNameShow() {
return customerCodeAndNameShow;
}
public void setCustomerCodeAndNameShow(String customerCodeAndNameShow) {
this.customerCodeAndNameShow = customerCodeAndNameShow;
}
public String getStdCodeAndNameShow() {
return stdCodeAndNameShow;
}
public void setStdCodeAndNameShow(String stdCodeAndNameShow) {
this.stdCodeAndNameShow = stdCodeAndNameShow;
}
public String getGroupShow() {
return groupShow;
}
public void setGroupShow(String groupShow) {
this.groupShow = groupShow;
}
}
......@@ -16,7 +16,7 @@ public interface VoucherService {
* @param pagingInfo 分页信息
* @return 分录信息
*/
OperationResultDto<Object> voucherSelectAdvancedByEntry(List<QueryConditionDto> listQueryCondition, VoucherSearchEnum mainRelation, boolean allJe, PagingDto pagingInfo);
OperationResultDto<Object> voucherSelectAdvancedByEntry(List<QueryConditionDto> listQueryCondition, VoucherSearchEnum mainRelation, boolean allJe, PagingDto pagingInfo) throws Exception;
/**
* 根据满足查询条件返回总数
......
package pwc.taxtech.atms.vat.service.impl;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.constant.VoucherSelect;
......@@ -8,11 +9,11 @@ import pwc.taxtech.atms.constant.enums.VoucherLevelEnum;
import pwc.taxtech.atms.constant.enums.VoucherSearchEnum;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.PagingDto;
import pwc.taxtech.atms.dto.vatdto.QueryConditionDto;
import pwc.taxtech.atms.dto.vatdto.VoucherTmplDto;
import pwc.taxtech.atms.dto.vatdto.*;
import pwc.taxtech.atms.vat.service.VoucherService;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
......@@ -23,14 +24,281 @@ public class VoucherServiceImpl extends VatAbstractService implements VoucherSer
JdbcTemplate jdbcTemplate;
@Override
public OperationResultDto<Object> voucherSelectAdvancedByEntry(List<QueryConditionDto> listQueryCondition, VoucherSearchEnum mainRelation, boolean allJe, PagingDto pagingInfo) {
return null;
public OperationResultDto<Object> voucherSelectAdvancedByEntry(List<QueryConditionDto> listQueryCondition, VoucherSearchEnum mainRelation, boolean allJe, PagingDto pagingInfo) throws Exception {
OperationResultDto<Object> result = new OperationResultDto<>();
StringBuffer exceptionString = new StringBuffer();
String sqlWhere = getSqlWhereCondition(listQueryCondition, mainRelation, allJe, exceptionString);
if (StringUtils.isNotBlank(exceptionString.toString())) {
result.setResult(false);
result.setResultMsg(exceptionString.toString());
return result;
}
String sql = StringUtils.EMPTY;
if (allJe) {
if (pagingInfo != null) {
sql = "SELECT" +
"`VoucherID`," +
"`Period`," +
"`Date`," +
"`GROUP`," +
"`ItemID`," +
"`VID`," +
"`Summary`," +
"e.`FullName`," +
"`Debit`," +
"`Credit`," +
"TB.`AcctCode`," +
"`CustomerCode`," +
"`CustomerName`," +
"e.StdCode," +
"TB.VoucherStd," +
"s.FullName AS StdName" +
"FROM" +
"(" +
"SELECT" +
"`VoucherID`," +
"c.`Period`," +
"`Date`," +
"c.`GROUP`," +
"`ItemID`," +
"c.`VID`," +
"`Summary`," +
"`Debit`," +
"`Credit`," +
"`AcctCode`," +
"`CustomerCode`," +
"`CustomerName`," +
"`StdCode` AS VoucherStd" +
"FROM" +
"(" +
"SELECT DISTINCT" +
"`Period`," +
"`GROUP`," +
"`VID`" +
"FROM" +
"(" +
"SELECT" +
"`Period`," +
"`GROUP`," +
"`VID`" +
"FROM" +
"Voucher " + sqlWhere +
") tbl" +
") abc" +
"LEFT JOIN Voucher c ON abc.`Period` = c.`Period`" +
"AND abc.`GROUP` = c.`GROUP`" +
"AND abc.`VID` = c.`VID`" +
") TB" +
"LEFT JOIN EnterpriseAccount e ON TB.AcctCode = e.AcctCode" +
"LEFT JOIN StandardAccount s ON e.StdCode = s. CODE" +
"ORDER BY" +
"`Period`," +
"`Date`," +
"`GROUP`," +
"`VID`" +
"LIMIT " + pagingInfo.getPageSize() * (pagingInfo.getPageIndex() - 1) + "," + pagingInfo.getPageSize();
} else {
sql = "SELECT" +
"`VoucherID`," +
"`Period`," +
"`Date`," +
"`GROUP`," +
"`ItemID`," +
"`VID`," +
"`Summary`," +
"e.`FullName`," +
"`Debit`," +
"`Credit`," +
"TB.`AcctCode`," +
"`CustomerCode`," +
"`CustomerName`," +
"e.StdCode," +
"TB.VoucherStd," +
"s.FullName AS StdName" +
"FROM" +
"(" +
"SELECT" +
"`VoucherID`," +
"c.`Period`," +
"`Date`," +
"c.`GROUP`," +
"`ItemID`," +
"c.`VID`," +
"`Summary`," +
"`Debit`," +
"`Credit`," +
"`AcctCode`," +
"`CustomerCode`," +
"`CustomerName`," +
"`StdCode` AS VoucherStd" +
"FROM" +
"(" +
"SELECT DISTINCT" +
"`Period`," +
"`GROUP`," +
"`VID`" +
"FROM" +
"(" +
"SELECT" +
"`Period`," +
"`GROUP`," +
"`VID`" +
"FROM" +
"Voucher " + sqlWhere +
") tbl" +
") abc" +
"LEFT JOIN Voucher c ON abc.`Period` = c.`Period`" +
"AND abc.`GROUP` = c.`GROUP`" +
"AND abc.`VID` = c.`VID`" +
") TB" +
"LEFT JOIN EnterpriseAccount e ON TB.AcctCode = e.AcctCode" +
"LEFT JOIN StandardAccount s ON e.StdCode = s. CODE" +
"ORDER BY" +
"`Period`," +
"`Date`," +
"`GROUP`," +
"`VID`";
}
} else {
if (pagingInfo != null) {
sql = "SELECT" +
"*" +
"FROM" +
"(" +
"SELECT" +
"`VoucherID`," +
"`Period`," +
"`Date`," +
"`Group`," +
"`ItemID`," +
"`VID`," +
"`Summary`," +
"e.`FullName`," +
"`Debit`," +
"`Credit`," +
"TB.`AcctCode`," +
"`CustomerCode`," +
"`CustomerName`," +
"e.StdCode," +
"Tb.VoucherStd AS VoucherStd," +
"s.FullName AS StdName" +
"FROM" +
"(" +
"SELECT" +
"`VoucherID`," +
"`Period`," +
"`Date`," +
"`Group`," +
"`ItemID`," +
"`VID`," +
"`Summary`," +
"`Debit`," +
"`Credit`," +
"`AcctCode`," +
"`CustomerCode`," +
"`CustomerName`," +
"`StdCode` AS VoucherStd" +
"FROM" +
"Voucher" + sqlWhere +
") TB" +
"LEFT JOIN EnterpriseAccount e ON TB.AcctCode = e.AcctCode" +
"LEFT JOIN StandardAccount s ON e.StdCode = s. CODE" +
") RowNumVoucher" +
"ORDER BY" +
"`Period`," +
"`Date`," +
"`Group`," +
"`VID`" +
"LIMIT " + pagingInfo.getPageSize() * (pagingInfo.getPageIndex() - 1) + "," + pagingInfo.getPageSize();
} else {
sql = "SELECT" +
"*" +
"FROM" +
"(" +
"SELECT" +
"`VoucherID`," +
"`Period`," +
"`Date`," +
"`Group`," +
"`ItemID`," +
"`VID`," +
"`Summary`," +
"e.`FullName`," +
"`Debit`," +
"`Credit`," +
"TB.`AcctCode`," +
"`CustomerCode`," +
"`CustomerName`," +
"e.StdCode," +
"Tb.VoucherStd AS VoucherStd," +
"s.FullName AS StdName" +
"FROM" +
"(" +
"SELECT" +
"`VoucherID`," +
"`Period`," +
"`Date`," +
"`Group`," +
"`ItemID`," +
"`VID`," +
"`Summary`," +
"`Debit`," +
"`Credit`," +
"`AcctCode`," +
"`CustomerCode`," +
"`CustomerName`," +
"`StdCode` AS VoucherStd" +
"FROM" +
"Voucher" + sqlWhere +
") TB" +
"LEFT JOIN EnterpriseAccount e ON TB.AcctCode = e.AcctCode" +
"LEFT JOIN StandardAccount s ON e.StdCode = s. CODE" +
") RowNumVoucher" +
"ORDER BY" +
"`Period`," +
"`Date`," +
"`Group`," +
"`VID`";
}
List<Map<String, Object>> queryForList = jdbcTemplate.queryForList(sql);
List<VoucherDto> voucherDtos = new ArrayList();
queryForList.forEach(a -> {
VoucherDto dto = new VoucherDto();
dto.setVoucherID(a.get("VoucherID").toString());
dto.setPeriod(Integer.parseInt(a.get("Period").toString()));
dto.setDate(DateTime.parse(a.get("Date").toString()).toDate());
dto.setGroup(a.get("Group").toString());
dto.setvID(a.get("VID").toString());
dto.setSummary(a.get("Summary").toString());
dto.setAcctCode(a.get("AcctCode").toString());
dto.setDebit(BigDecimal.valueOf(Double.valueOf(a.get("Debit").toString())));
dto.setCredit(BigDecimal.valueOf(Double.valueOf(a.get("Credit").toString())));
dto.setGroupShow(a.get("Group").toString() + "-" + a.get("VID").toString());
dto.setAcctCodeAndNameShow(a.get("AcctCode").toString() + (StringUtils.isNotBlank(a.get("FullName").toString()) ? "/" + a.get("FullName") : null));
dto.setCustomerCode(a.get("CustomerCode").toString());
dto.setCustomerName(a.get("CustomerName").toString());
dto.setCustomerCodeAndNameShow(a.get("CustomerCode").toString() + (StringUtils.isNotBlank(a.get("CustomerName").toString()) ? "/" + a.get("CustomerName").toString() : null));
dto.setStdCodeAndNameShow(a.get("StdCode").toString() + (StringUtils.isNotBlank(a.get("StdName").toString()) ? "/" + a.get("StdName").toString() : null));
dto.setStdCode(a.get("VoucherStd").toString());
voucherDtos.add(dto);
});
QueryVoucherDto dto = new QueryVoucherDto();
dto.setVoucherList(voucherDtos);
dto.setItemIDCount(voucherDtos.size());
dto.setCreditSum(new BigDecimal(voucherDtos.stream().mapToDouble(a -> a.getCredit().doubleValue()).summaryStatistics().getSum()));
dto.setDebitSum(new BigDecimal(voucherDtos.stream().mapToDouble(a -> a.getDebit().doubleValue()).summaryStatistics().getSum()));
dto.setVidCount((int) voucherDtos.stream().map(a -> new VIDCountDto(a.getvID(), a.getGroup(), a.getPeriod())).distinct().count());
result.setResult(true);
result.setData(dto);
}
return result;
}
@Override
public OperationResultDto<Object> voucherSelectAdvancedCount(List<QueryConditionDto> listQueryCondition, VoucherSearchEnum mainRelation, boolean isEntryShow, boolean allJe) throws Exception {
OperationResultDto<Object> result = new OperationResultDto<>();
StringBuffer exceptionString = new StringBuffer("");
StringBuffer exceptionString = new StringBuffer(StringUtils.EMPTY);
String sqlWhere = getSqlWhereCondition(listQueryCondition, mainRelation, allJe, exceptionString);
if (StringUtils.isNotBlank(exceptionString)) {
result.setResult(false);
......@@ -38,7 +306,7 @@ public class VoucherServiceImpl extends VatAbstractService implements VoucherSer
return result;
}
String sql = "";
String sql = StringUtils.EMPTY;
if (isEntryShow) {
if (allJe) {
sql = "select count(1) as TotalCount from" +
......@@ -60,7 +328,7 @@ public class VoucherServiceImpl extends VatAbstractService implements VoucherSer
private String getSqlWhereCondition(List<QueryConditionDto> listQueryCondition, VoucherSearchEnum mainRelation, boolean allJe, StringBuffer exceptionString) throws Exception {
//what does this statement used for?
exceptionString = new StringBuffer("");
exceptionString = new StringBuffer(StringUtils.EMPTY);
if (mainRelation != VoucherSearchEnum.S_AndAll && mainRelation != VoucherSearchEnum.S_OrAll) {
throw new Exception("条件关系定义错误");
......@@ -248,7 +516,7 @@ public class VoucherServiceImpl extends VatAbstractService implements VoucherSer
break;
}
temp.setSql(sb.toString());
String acctStrs = "";
String acctStrs = StringUtils.EMPTY;
if (columnName.equals("EnterpriseAccount.`Name`")) {
acctStrs = "select AcctCode from EnterpriseAccount where " + temp.getSql();
......@@ -282,7 +550,7 @@ public class VoucherServiceImpl extends VatAbstractService implements VoucherSer
sqlWhere.append(" where");
}
for (VoucherTmplDto t : smallTemp) {
String logic = "";
String logic = StringUtils.EMPTY;
if (t.getLogic().equals(VoucherSearchEnum.S_OrAll)) {
logic = " OR";
} else if (t.getLogic().equals(VoucherSearchEnum.S_AndAll)) {
......@@ -296,4 +564,4 @@ public class VoucherServiceImpl extends VatAbstractService implements VoucherSer
}
return sqlWhere.toString();
}
}
}
\ No newline at end of file
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