Commit 039db78b authored by chase's avatar chase

新增税金查询公式(按名字)

parent 59e0d05f
package pwc.taxtech.atms.dto.vatdto;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.ValueEval;
import java.util.ArrayList;
import java.util.List;
import static pwc.taxtech.atms.common.util.FormulaUtil.resolverInteger;
import static pwc.taxtech.atms.common.util.FormulaUtil.resolverString;
import static pwc.taxtech.atms.exception.Exceptions.BAD_BBVO_PARAMS;
public class WPNAMEParasBo {
private String reportCode;
private Integer columnIndex;
private Integer rowColumnIndex;
private String rowName;
private String formulaExpression;
private List<PeriodCellDataTemplate> expressionData = new ArrayList<>();
public static class PeriodCellDataTemplate {
Integer period;
Long cellTemplateId;
@Override
public String toString() {
return period + ":" + cellTemplateId;
}
public PeriodCellDataTemplate(Integer period, Long cellTemplateId) {
this.period = period;
this.cellTemplateId = cellTemplateId;
}
}
public void putPeriodCellTempate(Integer period, Long cellTemplateId) {
if (period < 1 || period > 12 || cellTemplateId < 0) throw BAD_BBVO_PARAMS;
expressionData.add(new PeriodCellDataTemplate(period, cellTemplateId));
}
public WPNAMEParasBo(ValueEval[] args, OperationEvaluationContext ec) throws EvaluationException {
StringBuilder expression = new StringBuilder("");
begin(expression);
reportCode = resolverString(args, ec, 0);
concatPara(expression, reportCode);
try {
rowColumnIndex = resolverInteger(args, ec, 1);
split(expression);
concatPara(expression, rowColumnIndex);
} catch (Exception e) {
String columnStr = resolverString(args, ec, 1);
split(expression);
concatPara(expression, columnStr);
int rtn = 0;
columnStr = columnStr.toUpperCase();
char[] excelCol = columnStr.toCharArray();
for (int i = columnStr.length() - 1; i >= 0; i--) {
if (excelCol[i] >= 'A' && excelCol[i] <= 'Z') {
rtn += ((int) Math.pow(26, excelCol.length - 1 - i) * (excelCol[i] - 64));
} else {
rtn = -1;
}
}
rowColumnIndex = rtn;
}
rowName = resolverString(args, ec, 2);
split(expression);
concatPara(expression, rowName);
try {
columnIndex = resolverInteger(args, ec, 3);
split(expression);
concatPara(expression, columnIndex);
} catch (Exception e) {
String columnStr = resolverString(args, ec, 3);
split(expression);
concatPara(expression, columnStr);
int rtn = 0;
columnStr = columnStr.toUpperCase();
char[] excelCol = columnStr.toCharArray();
for (int i = columnStr.length() - 1; i >= 0; i--) {
if (excelCol[i] >= 'A' && excelCol[i] <= 'Z') {
rtn += ((int) Math.pow(26, excelCol.length - 1 - i) * (excelCol[i] - 64));
} else {
rtn = -1;
}
}
columnIndex = rtn;
}
end(expression);
formulaExpression = expression.toString();
}
private StringBuilder begin(StringBuilder expression) {
return expression.append("WPNAME(");
}
private StringBuilder end(StringBuilder expression) {
return expression.append(")");
}
private StringBuilder split(StringBuilder expression) {
return expression.append(",");
}
private StringBuilder concatPara(StringBuilder expression, String para) {
return expression.append("\"").append(para).append("\"");
}
private StringBuilder concatPara(StringBuilder expression, Integer para) {
return expression.append(para);
}
public WPNAMEParasBo(WPNAMEParasBo otherBo) {
this.reportCode = otherBo.reportCode;
this.columnIndex = otherBo.getColumnIndex();
this.rowName = otherBo.rowName;
this.formulaExpression = otherBo.formulaExpression;
}
public String expression() {
return formulaExpression;
}
public String getReportCode() {
return this.reportCode;
}
public void setReportCode(String reportCode) {
this.reportCode = reportCode;
}
public Integer getColumnIndex() {
return this.columnIndex;
}
public void setColumnIndex(Integer columnIndex) {
this.columnIndex = columnIndex;
}
public String getRowName() {
return rowName;
}
public void setRowName(String rowName) {
this.rowName = rowName;
}
public Integer getRowColumnIndex() {
return rowColumnIndex;
}
public void setRowColumnIndex(Integer rowColumnIndex) {
this.rowColumnIndex = rowColumnIndex;
}
public String getFormulaExpression() {
return this.formulaExpression;
}
public void setFormulaExpression(String formulaExpression) {
this.formulaExpression = formulaExpression;
}
public List<PeriodCellDataTemplate> getExpressionData() {
return this.expressionData;
}
public void setExpressionData(List<PeriodCellDataTemplate> expressionData) {
this.expressionData = expressionData;
}
@Override
public String toString() {
return "BBParasBo{" +
"reportCode='" + reportCode + '\'' +
", columnIndex=" + columnIndex +
", rowColumnIndex=" + rowColumnIndex +
", rowName=" + rowName +
'}';
}
}
package pwc.taxtech.atms.vat.service.impl.report.functions;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pwc.taxtech.atms.common.util.MyAsserts;
import pwc.taxtech.atms.constant.DataSourceName;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.dpo.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dto.vatdto.BBParasBo;
import pwc.taxtech.atms.dto.vatdto.CurrentPeriodBo;
import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto;
import pwc.taxtech.atms.dto.vatdto.WPNAMEParasBo;
import pwc.taxtech.atms.entity.Project;
import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.exception.FormulaException;
import pwc.taxtech.atms.vat.entity.PeriodCellData;
import pwc.taxtech.atms.vat.entity.PeriodDataSource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class WPNAME extends FunctionBase implements FreeRefFunction {
static final Logger LOGGER = LoggerFactory.getLogger(WPNAME.class);
final static ValueEval defaultEval = new StringEval("0");
final static BigDecimal defaultBigDecimal = new BigDecimal("0");
public WPNAME(FormulaContext context) {
super(context);
}
@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
try {
return wrapExceptionEval(args, ec);
} catch (Exception e) {
if (e instanceof FormulaException)
LOGGER.warn("Formula Exception || {}", e.getMessage());
e.printStackTrace();
return defaultEval;
}
}
public ValueEval wrapExceptionEval(ValueEval[] args, OperationEvaluationContext ec) throws Exception {
List<Object> ds = new ArrayList<>();
return new NumberEval(bb(new WPNAMEParasBo(args, ec), ec, ds, null).doubleValue());
}
public BigDecimal bb(WPNAMEParasBo bo, OperationEvaluationContext ec, List<Object> dataSource, WPNAMEParasBo rootBo) throws Exception {
CurrentPeriodBo curPeriod = CurrentPeriodBo.getPeriod(formulaContext.getPeriod(), formulaContext.getPeriod());
curPeriod.setCurYear(formulaContext.getYear());
ReportCellDataSourceDto nullCellDto = new ReportCellDataSourceDto();
dataSource.add(nullCellDto);
BigDecimal cellValue = BigDecimal.ZERO;
CellTemplatePerGroupDto cellTemplateData = null;
try {
List<CellTemplatePerGroupDto> cellTemplateDataList;
//根据目标列+名称定位数据行,再根据参数列+数据行定位sheet单元格
cellTemplateDataList = agent.getCellTemplateByNameAndIndex(formulaContext.getReportTemplateGroupId(),
formulaContext.getProjectId(), bo.getReportCode(), bo.getRowColumnIndex()-1,bo.getRowName(), bo.getColumnIndex() - 1, formulaContext.getPeriod());
MyAsserts.assertNotEmpty(cellTemplateDataList, Exceptions.BB_CELL_TEMP_NULL);
cellTemplateData = cellTemplateDataList.get(0);
int index = ec.getWorkbook().getSheetIndex(bo.getReportCode());
cellValue = getCellValue(index, ec, formulaContext, agent, cellTemplateData.getRowIndex(), bo.getColumnIndex() - 1,
Long.parseLong(cellTemplateData.getCellTemplateId()));
nullCellDto.extractFromGroup(bo, formulaContext.getPeriod(), formulaContext.getYear(), cellTemplateData);
nullCellDto.setAmount(cellValue);
return cellValue;
} catch (Exception e) {
logger.warn("[BB_Exception] some error {}", bo.toString());
throw e;
} finally {
if (rootBo == null) {
LOGGER.warn("[BB_Exception] error for bb cacls for {} and current for {}", bo.toString(), curPeriod.toString());
Long dataSourceId = saveDataSource(ec, dataSource, FormulaDataSourceDetailType.ReportCellDataSourceDto,
cellValue, formulaContext.getPeriod(),
formulaContext.getReportTemplateGroupId(), cellTemplateData.getColumnIndex(), cellTemplateData.getRowIndex(),
formulaContext.getProjectId());
saveFormulaBlock(formulaContext.getPeriod(), ec,
bo.expression(), cellValue, dataSourceId, formulaContext.getProjectId());
}
}
}
}
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
update_by, update_by,
project_id) project_id)
VALUES VALUES
<foreach collection="list" item="item"> <foreach collection="list" item="item" separator=",">
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<choose> <choose>
<when test="item.id != null">#{item.id,jdbcType=INTEGER},</when> <when test="item.id != null">#{item.id,jdbcType=INTEGER},</when>
......
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