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

add function SGSR method

parent b3ec20cc
package pwc.taxtech.atms.vat.service.impl.report.functions;
public class FormulaContext {
private Integer period;
private Integer year;
public Integer getPeriod() {
return period;
}
public void setPeriod(Integer period) {
this.period = period;
}
public Integer getYear() {
return year;
}
public void setYear(Integer year) {
this.year = year;
}
}
package pwc.taxtech.atms.vat.service.impl.report.functions;
public class FormulaHelper {
/**
* Excel column index begin 1
*
* @param colStr
* @param length
* @return
*/
public static int excelColStrToNum(String colStr, int length) {
int num = 0;
int result = 0;
for (int i = 0; i < length; i++) {
char ch = colStr.charAt(length - i - 1);
num = (int) (ch - 'A' + 1);
num *= Math.pow(26, i);
result += num;
}
return result;
}
/**
* Excel column index begin 1
*
* @param columnIndex
* @return
*/
public static String excelColIndexToStr(int columnIndex) {
if (columnIndex <= 0) {
return null;
}
String columnStr = "";
columnIndex--;
do {
if (columnStr.length() > 0) {
columnIndex--;
}
columnStr = ((char) (columnIndex % 26 + (int) 'A')) + columnStr;
columnIndex = (int) ((columnIndex - columnIndex % 26) / 26);
} while (columnIndex > 0);
return columnStr;
}
public static int getPeriod(int parameterPeriod, int[] yearOffset, FormulaContext formulaFunctionContext) {
yearOffset[0] = 0;
if (parameterPeriod == -99) {
return parameterPeriod;
} else if (parameterPeriod <= -1) {
int period = parameterPeriod + formulaFunctionContext.getPeriod();
while (period <= 0) {
yearOffset[0]--;
period += 12;
//throw new NotImplementedException();
}
return period;
} else if (parameterPeriod == 0) {
return formulaFunctionContext.getPeriod();
} else {
return parameterPeriod;
}
}
public static int getYear(int parameterYear, FormulaContext formulaContext) {
if (parameterYear <= -1) {
return parameterYear + formulaContext.getYear();
} else if (parameterYear == 0) {
return formulaContext.getYear();
} else {
return parameterYear;
}
}
}
package pwc.taxtech.atms.vat.service.impl.report.functions;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.OperandResolver;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
public class SGSRFunction implements FreeRefFunction {
private FormulaContext formulaContext;
public SGSRFunction(FormulaContext formulaContext){
this.formulaContext = formulaContext;
}
@Override
public ValueEval evaluate(ValueEval[] valueEvals, OperationEvaluationContext operationEvaluationContext) {
try {
int period, year, colIndex, rowIndex;
String reportCode;
if (valueEvals.length > 4) {
ValueEval v5 = OperandResolver.getSingleValue(valueEvals[4],
operationEvaluationContext.getRowIndex(),
operationEvaluationContext.getColumnIndex());
year = OperandResolver.coerceValueToInt(v5);
} else {
year = 0;
}
ValueEval v1 = OperandResolver.getSingleValue(valueEvals[0],
operationEvaluationContext.getRowIndex(),
operationEvaluationContext.getColumnIndex());
reportCode = OperandResolver.coerceValueToString(v1);
ValueEval v2 = OperandResolver.getSingleValue(valueEvals[1],
operationEvaluationContext.getRowIndex(),
operationEvaluationContext.getColumnIndex());
String cIndex = OperandResolver.coerceValueToString(v2);
colIndex = FormulaHelper.excelColStrToNum(cIndex, cIndex.length());
ValueEval v3 = OperandResolver.getSingleValue(valueEvals[2],
operationEvaluationContext.getRowIndex(),
operationEvaluationContext.getColumnIndex());
rowIndex = OperandResolver.coerceValueToInt(v3);
ValueEval v4 = OperandResolver.getSingleValue(valueEvals[3],
operationEvaluationContext.getRowIndex(),
operationEvaluationContext.getColumnIndex());
period = OperandResolver.coerceValueToInt(v4);
int curYear, curPeriod;
if(reportCode.startsWith("VAT")){
int[] yearOffSet = {};
curPeriod =FormulaHelper.getPeriod(period,yearOffSet,formulaContext);
curYear = FormulaHelper.getYear(year,formulaContext)+yearOffSet[0];
}
else if(reportCode.startsWith("CIT.")){
curYear=FormulaHelper.getYear(year,formulaContext);
curPeriod=0;
}
else{
}
} catch (EvaluationException e) {
e.printStackTrace();
}
return null;
}
}
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