Commit e1380145 authored by frank.xa.zhang's avatar frank.xa.zhang

complete api for data view---VoucherSelectAdvancedCount

parent c62cf22c
package pwc.taxtech.atms.constant;
public class VoucherSelect {
public static final String S_EqualAnyKey = "等于任意一个关键词";
public static final String S_AnyHeaderKey = "以任意一个关键词开头";
public static final String S_AllKey = "包含全部关键词";
public static final String S_ContainAnyKey = "包含任意一个关键词";
public static final String S_AndAll = "与";
public static final String S_OrAll = "或";
public static final String S_Manual = "手工凭证";
public static final String S_Industry = "企业凭证";
public static final String S_Equal = "等于";
public static final String S_Greater = "大于";
public static final String S_GreaterEqual = "大于等于";
public static final String S_Include = "包含";
public static final String S_JFLJ = "借方累计金额";
public static final String S_Less = "小于";
public static final String S_LessEqual = "小于等于";
public static final String S_NotEqual = "不等于";
public static final String S_NotInclude = "不包含";
public static final String S_Or = "或者";
public static final String S_And = "并且";
public static final String S_Condition = "条件间的关系";
public static final String S_CorpAcctCoding = "科目代码";
public static final String S_CorpAcctName = "科目名称";
public static final String S_Period = "会计期间";
public static final String S_VoucherType = "凭证类型";
public static final String S_VoucherVID = "凭证编号";
public static final String S_VoucherSummary = "摘要关键字";
public static final String S_CustomerCode = "往来核算代码";
public static final String S_CustomerName = "往来核算名称";
public static final String S_Date = "凭证日期";
public static final String S_Debit = "借方金额";
public static final String S_Credit = "贷方金额";
public static final String S_Source = "凭证来源";
public static final String S_AllJe = "显示全部凭证";
public static final String S_DAcctCode = "借方科目代码";
public static final String S_CAcctCode = "贷方科目代码";
public static final String S_VSummary = "摘要包含";
public static final String S_TaxType = "税种";
public static final String S_NegativeNum = "是否包含借方红字或贷方红字";
}
package pwc.taxtech.atms.constant.enums;
public enum VoucherLevelEnum {
FirstSort(1,"运算字符查询"),
SecondSort(2,"like字段查询"),
ThirdSort(3,"IsNull查询");
private int code;
private String description;
VoucherLevelEnum(int code, String description) {
this.code = code;
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
}
package pwc.taxtech.atms.dto.vatdto;
import pwc.taxtech.atms.constant.enums.VoucherSearchEnum;
import java.util.List;
public class VoucherTmplDto {
private String columnName;
private String columnText;
private String lkh;
private VoucherSearchEnum logic;
private String relation;
private String rkh;
private int row;
private int sort;
private String sql;
private List<String> sqlList;
private int tmplCode;
private int tmplId;
private String tmplName;
private int type;
private String value;
public String getColumnName() {
return columnName;
}
public void setColumnName(String columnName) {
this.columnName = columnName;
}
public String getColumnText() {
return columnText;
}
public void setColumnText(String columnText) {
this.columnText = columnText;
}
public String getLkh() {
return lkh;
}
public void setLkh(String lkh) {
this.lkh = lkh;
}
public VoucherSearchEnum getLogic() {
return logic;
}
public void setLogic(VoucherSearchEnum logic) {
this.logic = logic;
}
public String getRelation() {
return relation;
}
public void setRelation(String relation) {
this.relation = relation;
}
public String getRkh() {
return rkh;
}
public void setRkh(String rkh) {
this.rkh = rkh;
}
public int getRow() {
return row;
}
public void setRow(int row) {
this.row = row;
}
public int getSort() {
return sort;
}
public void setSort(int sort) {
this.sort = sort;
}
public String getSql() {
return sql;
}
public void setSql(String sql) {
this.sql = sql;
}
public List<String> getSqlList() {
return sqlList;
}
public void setSqlList(List<String> sqlList) {
this.sqlList = sqlList;
}
public int getTmplCode() {
return tmplCode;
}
public void setTmplCode(int tmplCode) {
this.tmplCode = tmplCode;
}
public int getTmplId() {
return tmplId;
}
public void setTmplId(int tmplId) {
this.tmplId = tmplId;
}
public String getTmplName() {
return tmplName;
}
public void setTmplName(String tmplName) {
this.tmplName = tmplName;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
......@@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.common.datasource.DataSourceConfig;
......@@ -95,4 +96,9 @@ public class DataSourcePoolService extends AbstractRoutingDataSource {
return new SqlSessionTemplate(sqlSessionFactory);
}
@Bean
public JdbcTemplate dynamicJdbcTemplate(@Qualifier("DynamicDataSource")DataSource dynamicDataSource) {
return new JdbcTemplate(dynamicDataSource);
}
}
......@@ -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);
/**
* 根据满足查询条件返回总数
......@@ -26,5 +26,5 @@ public interface VoucherService {
* @param allJe 显示全部凭证
* @return 满足条件的总条数
*/
OperationResultDto<Object> VoucherSelectAdvancedCount(List<QueryConditionDto> listQueryCondition, VoucherSearchEnum mainRelation, boolean isEntryShow, boolean allJe);
OperationResultDto<Object> voucherSelectAdvancedCount(List<QueryConditionDto> listQueryCondition, VoucherSearchEnum mainRelation, boolean isEntryShow, boolean allJe) throws Exception;
}
package pwc.taxtech.atms.vat.service.impl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.constant.VoucherSelect;
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.vat.service.VoucherService;
import java.util.List;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class VoucherServiceImpl extends VatAbstractService implements VoucherService {
@Resource(name = "dynamicJdbcTemplate")
JdbcTemplate jdbcTemplate;
@Override
public OperationResultDto<Object> VoucherSelectAdvancedByEntry(List<QueryConditionDto> listQueryCondition, VoucherSearchEnum mainRelation, boolean allJe, PagingDto pagingInfo) {
public OperationResultDto<Object> voucherSelectAdvancedByEntry(List<QueryConditionDto> listQueryCondition, VoucherSearchEnum mainRelation, boolean allJe, PagingDto pagingInfo) {
return null;
}
@Override
public OperationResultDto<Object> VoucherSelectAdvancedCount(List<QueryConditionDto> listQueryCondition, VoucherSearchEnum mainRelation, boolean isEntryShow, boolean allJe) {
public OperationResultDto<Object> voucherSelectAdvancedCount(List<QueryConditionDto> listQueryCondition, VoucherSearchEnum mainRelation, boolean isEntryShow, boolean allJe) throws Exception {
OperationResultDto<Object> result = new OperationResultDto<>();
String exceptionString = "";
StringBuffer exceptionString = new StringBuffer("");
String sqlWhere = getSqlWhereCondition(listQueryCondition, mainRelation, allJe, exceptionString);
if (StringUtils.isNotBlank(exceptionString)) {
result.setResult(false);
result.setResultMsg(exceptionString);
result.setResultMsg(exceptionString.toString());
return result;
}
......@@ -33,20 +42,258 @@ public class VoucherServiceImpl extends VatAbstractService implements VoucherSer
if (isEntryShow) {
if (allJe) {
sql = "select count(1) as TotalCount from" +
" (select distinct [Period],[Group],[VID] from" +
" (select [Period],[Group],[VID] from Voucher " + sqlWhere + ")TB)abc" +
" left join Voucher c on abc.[Period]=c.[Period] and abc.[Group]=c.[Group] and abc.[VID]=c.[VID]";
" (select distinct Period,`Group`,VID from" +
" (select Period,`Group`,VID from Voucher " + sqlWhere + ")TB)abc" +
" left join Voucher c on abc.Period=c.Period and abc.`Group`=c.`Group` and abc.VID=c.VID";
} else {
sql = "select count(1) as TotalCount from Voucher " + sqlWhere;
}
} else {
sql = "Select count(1) as TotalCount from (select [Period],[Group],[VID] from Voucher " + sqlWhere + " group by [Period],[Group],[VID])TB";
sql = "Select count(1) as TotalCount from (select Period,`Group`,VID from Voucher " + sqlWhere + " group by Period,`Group`,VID)TB";
}
int total = jdbcTemplate.queryForObject(sql, int.class);
result.setResult(true);
result.setData(total);
return null;
}
private String getSqlWhereCondition(List<QueryConditionDto> listQueryCondition, VoucherSearchEnum mainRelation, boolean allJe, String exceptionString) {
return "";
private String getSqlWhereCondition(List<QueryConditionDto> listQueryCondition, VoucherSearchEnum mainRelation, boolean allJe, StringBuffer exceptionString) throws Exception {
//what does this statement used for?
exceptionString = new StringBuffer("");
if (mainRelation != VoucherSearchEnum.S_AndAll && mainRelation != VoucherSearchEnum.S_OrAll) {
throw new Exception("条件关系定义错误");
}
List<VoucherTmplDto> tmpls = new ArrayList<>();
for (QueryConditionDto queryConditionDto : listQueryCondition) {
switch (queryConditionDto.getConditionName()) {
case VoucherSelect.S_CorpAcctCoding:
tmpls.add(createQueryScriptByTmplList(Arrays.asList(queryConditionDto.getSearchValue().split(" "))
, VoucherSearchEnum.values()[queryConditionDto.getSearchKeyWord()]
, "`AcctCode`"
, mainRelation
, null));
break;
case VoucherSelect.S_CorpAcctName:
tmpls.add(createQueryScriptByTmplList(Arrays.asList(queryConditionDto.getSearchValue().split(" "))
, VoucherSearchEnum.values()[queryConditionDto.getSearchKeyWord()]
, "EnterpriseAccount.`Name`"
, mainRelation
, null));
break;
case VoucherSelect.S_VoucherType:
tmpls.add(createQueryScriptByTmplList(Arrays.asList(queryConditionDto.getSearchValue().split(" "))
, VoucherSearchEnum.values()[queryConditionDto.getSearchKeyWord()]
, "`Group`"
, mainRelation
, null));
break;
case VoucherSelect.S_VoucherVID:
tmpls.add(createQueryScriptByTmplList(Arrays.asList(queryConditionDto.getSearchValue().split(" "))
, VoucherSearchEnum.values()[queryConditionDto.getSearchKeyWord()]
, "`VID`"
, mainRelation
, null));
break;
case VoucherSelect.S_VoucherSummary:
tmpls.add(createQueryScriptByTmplList(Arrays.asList(queryConditionDto.getSearchValue().split(" "))
, VoucherSearchEnum.values()[queryConditionDto.getSearchKeyWord()]
, "`Summary`"
, mainRelation
, null));
break;
case VoucherSelect.S_Period:
tmpls.add(createQueryScriptByTmplList(Arrays.asList(queryConditionDto.getSearchValue().split(" "))
, VoucherSearchEnum.values()[queryConditionDto.getSearchKeyWord()]
, "`Period`"
, mainRelation
, null));
break;
case VoucherSelect.S_Debit:
tmpls.add(createQueryScriptByTmplList(Arrays.asList(queryConditionDto.getSearchValue().split(" "))
, VoucherSearchEnum.values()[queryConditionDto.getSearchKeyWord()]
, "`Debit`"
, mainRelation
, null));
break;
case VoucherSelect.S_Credit:
tmpls.add(createQueryScriptByTmplList(Arrays.asList(queryConditionDto.getSearchValue().split(" "))
, VoucherSearchEnum.values()[queryConditionDto.getSearchKeyWord()]
, "`Credit`"
, mainRelation
, null));
break;
case VoucherSelect.S_Date:
tmpls.add(createQueryScriptByTmplList(Arrays.asList(queryConditionDto.getSearchValue().split(" "))
, VoucherSearchEnum.values()[queryConditionDto.getSearchKeyWord()]
, "`Date`"
, mainRelation
, null));
break;
case VoucherSelect.S_CustomerCode:
tmpls.add(createQueryScriptByTmplList(Arrays.asList(queryConditionDto.getSearchValue().split(" "))
, VoucherSearchEnum.values()[queryConditionDto.getSearchKeyWord()]
, "Voucher.CustomerCode"
, mainRelation
, null));
break;
case VoucherSelect.S_CustomerName:
tmpls.add(createQueryScriptByTmplList(Arrays.asList(queryConditionDto.getSearchValue().split(" "))
, VoucherSearchEnum.values()[queryConditionDto.getSearchKeyWord()]
, "Voucher.CustomerName"
, mainRelation
, null));
break;
default:
throw new Exception("未处理的条件类型:" + queryConditionDto.getConditionName());
}
}
tmpls.forEach(p -> {
if (StringUtils.isBlank(p.getSql())) {
tmpls.remove(p);
}
});
return getSqlWhereCondition(tmpls);
}
private VoucherTmplDto createQueryScriptByTmplList(List<String> strList, VoucherSearchEnum relation, String columnName, VoucherSearchEnum logic, String strValue) throws Exception {
VoucherTmplDto temp = new VoucherTmplDto();
temp.setLogic(logic);
StringBuffer sb = new StringBuffer();
sb.append("(");
int count = strList.size();
switch (relation) {
case S_EqualAnyKey:
for (int i = 0; i < count; i++) {
sb.append(columnName + "=`" + strList.get(i) + "`" + (i < (count - 1) ? " or " : ")"));
}
temp.setSort(VoucherLevelEnum.FirstSort.getCode());
break;
case S_AnyHeaderKey:
for (int i = 0; i < count; i++) {
sb.append(columnName + "=`" + strList.get(i) + "`" + (i < (count - 1) ? " or " : ")"));
}
temp.setSort(VoucherLevelEnum.SecondSort.getCode());
break;
case S_AllKey:
for (int i = 0; i < count; i++) {
sb.append(columnName + "like'" + strList.get(i) + "'" + (i < (count - 1) ? " and " : ")"));
}
temp.setSort(VoucherLevelEnum.SecondSort.getCode());
break;
case S_ContainAnyKey:
for (int i = 0; i < count; i++) {
sb.append(columnName + "like'" + strList.get(i) + "'" + (i < (count - 1) ? " or " : ")"));
}
temp.setSort(VoucherLevelEnum.SecondSort.getCode());
break;
case S_Equal:
sb.append(columnName + " ='" + strValue + "'");
temp.setSort(VoucherLevelEnum.FirstSort.getCode());
break;
case S_Greater:
sb.append(columnName + " >'" + strValue + "'");
temp.setSort(VoucherLevelEnum.FirstSort.getCode());
break;
case S_GreaterEqual:
sb.append(columnName + " >='" + strValue + "'");
temp.setSort(VoucherLevelEnum.FirstSort.getCode());
break;
case S_Less: //小于
sb.append(columnName + "< '" + strValue + "')");
temp.setSort(VoucherLevelEnum.FirstSort.getCode());
break;
case S_LessEqual: //小于等于
sb.append(columnName + "<= '" + strValue + "')");
temp.setSort(VoucherLevelEnum.FirstSort.getCode());
break;
case S_Manual:
sb.append(columnName + "=1");
temp.setSort(VoucherLevelEnum.FirstSort.getCode());
break;
case S_Industry:
sb.append(columnName + " is null");
temp.setSort(VoucherLevelEnum.ThirdSort.getCode());
break;
case S_FromTo:
if (strList.size() != 2) {
throw new Exception("数据格式错误");
}
if (!strList.get(0).toLowerCase().equals("null") && !strList.get(1).toLowerCase().equals("null")) {
if (columnName.equals("`Debit`") || columnName.equals("`Credit`")) {
sb.append(columnName + ">=" + Double.valueOf(strList.get(0)) + " And " + columnName + " <=" + Double.valueOf(strList.get(1)) + ")");
} else {
sb.append(columnName + ">='" + strList.get(0) + "' And " + columnName + " <= '" + strList.get(1) + "')");
}
} else if (strList.get(0).toLowerCase().equals("null") && strList.get(1).toLowerCase().equals("null")) {
break;
} else if (!strList.get(0).toLowerCase().equals("null") && strList.get(1).toLowerCase().equals("null")) {
if (columnName.equals("`Debit`") || columnName.equals("`Credit`")) {
sb.append(columnName + ">=" + Double.valueOf(strList.get(0)) + ")");
} else {
sb.append(columnName + ">='" + strList.get(0) + "')");
}
} else if (strList.get(0).toLowerCase().equals("null") && !strList.get(1).toLowerCase().equals("null")) {
if (columnName.equals("`Debit`") || columnName.equals("`Credit`")) {
sb.append(columnName + " <=" + Double.valueOf(strList.get(1)) + ")");
} else {
sb.append(columnName + " <= '" + strList.get(1) + "')");
}
}
temp.setSort(VoucherLevelEnum.FirstSort.getCode());
break;
}
temp.setSql(sb.toString());
String acctStrs = "";
if (columnName.equals("EnterpriseAccount.`Name`")) {
acctStrs = "select AcctCode from EnterpriseAccount where " + temp.getSql();
List<Map<String, Object>> result = jdbcTemplate.queryForList(acctStrs);
int num = result.size();
if (num > 0) {
sb = new StringBuffer();
sb.append("(");
for (int idx = 0; idx < num; idx++) {
Map<String, Object> item = result.get(idx);
sb.append("AcctCode='" + item.get("AcctCode") + "'" + (idx < (num - 1) ? " or " : ")"));
}
temp.setSort(VoucherLevelEnum.FirstSort.getCode());
temp.setSql(sb.toString());
} else {
temp.setSql("(AcctCode is null)");
temp.setSort(VoucherLevelEnum.ThirdSort.getCode());
}
}
return temp;
}
private String getSqlWhereCondition(List<VoucherTmplDto> tmplList) throws Exception {
List<VoucherTmplDto> smallTemp = tmplList.stream().sorted(Comparator.comparing(VoucherTmplDto::getSort).reversed()).collect(Collectors.toList());
int count = 1;
int tCount = smallTemp.size();
StringBuilder sqlWhere = new StringBuilder();
if (tCount > 0) {
sqlWhere.append(" where");
}
for (VoucherTmplDto t : smallTemp) {
String logic = "";
if (t.getLogic().equals(VoucherSearchEnum.S_OrAll)) {
logic = " OR";
} else if (t.getLogic().equals(VoucherSearchEnum.S_AndAll)) {
logic = " AND";
} else {
throw new Exception("未处理的条件关系:" + t.getLogic().toString());
}
sqlWhere.append(" ").append(t.getSql()).append(count < tCount ? logic + " " : " ");
count++;
}
return sqlWhere.toString();
}
}
......@@ -11,39 +11,39 @@
<!-- DruidDataSource数据源配置) -->
<!-- See: https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_DruidDataSource%E5%8F%82%E8%80%83%E9%85%8D%E7%BD%AE -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<!-- 基本属性 url、user、password -->
<property name="url" value="${jdbc_url}" />
<property name="username" value="${jdbc_user}" />
<property name="password" value="${jdbc_password}" />
init-method="init" destroy-method="close">
<!-- 基本属性 url、user、password -->
<property name="url" value="${jdbc_url}" />
<property name="username" value="${jdbc_user}" />
<property name="password" value="${jdbc_password}" />
<!-- 配置初始化大小、最小、最大 -->
<property name="initialSize" value="${atms.config.druid.initialSize:0}" />
<property name="minIdle" value="${atms.config.druid.minIdle:1}" />
<property name="maxActive" value="${atms.config.druid.maxActive:20}" />
<!-- 配置初始化大小、最小、最大 -->
<property name="initialSize" value="${atms.config.druid.initialSize:0}" />
<property name="minIdle" value="${atms.config.druid.minIdle:1}" />
<property name="maxActive" value="${atms.config.druid.maxActive:20}" />
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="${atms.config.druid.maxWait:60000}" />
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="${atms.config.druid.maxWait:60000}" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="${atms.config.druid.timeBetweenEvictionRunsMillis:60000}" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="${atms.config.druid.timeBetweenEvictionRunsMillis:60000}" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="${atms.config.druid.minEvictableIdleTimeMillis:300000}" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="${atms.config.druid.minEvictableIdleTimeMillis:300000}" />
<property name="validationQuery" value="${jdbc_validationQuery:SELECT 'x'" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="validationQuery" value="${jdbc_validationQuery:SELECT 'x'" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
<property name="poolPreparedStatements" value="true" />
<property name="maxPoolPreparedStatementPerConnectionSize"
value="20" />
<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
<property name="poolPreparedStatements" value="true" />
<property name="maxPoolPreparedStatementPerConnectionSize"
value="20" />
<!-- 配置监控统计拦截的filters -->
<property name="filters" value="stat" />
</bean>
<!-- 配置监控统计拦截的filters -->
<property name="filters" value="stat" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
......
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