Commit 4124b3b9 authored by zhkwei's avatar zhkwei

CIT期末余额公式

parent ec91e3be
......@@ -41,28 +41,47 @@ public class RSUMIFParasBo {
expressionData.add(new PeriodCellDataTemplate(period, cellTemplateId));
}
public String getExpression(ValueEval[] args, OperationEvaluationContext ec) throws EvaluationException {
public String getExpression(ValueEval[] args, OperationEvaluationContext ec) throws EvaluationException {
StringBuilder expression = new StringBuilder("");
begin(expression);
for(int i = 0 ; i< args.length; i++){
if(i >= 4){
for (int i = 0; i < args.length; i++) {
if (i >= 4) {
concatPara(expression, resolverInteger(args, ec, i));
}else{
} else {
concatPara(expression, resolverString(args, ec, i));
}
if(i == args.length-1){
if (i == args.length - 1) {
continue;
}
split(expression);
}
end(expression);
return expression.toString();
return expression.toString();
}
public String getQMYEExpression(Integer subjectType, String subjectCode, Integer year, Integer period, OperationEvaluationContext ec) throws EvaluationException {
StringBuilder expression = new StringBuilder("");
beginQMYE(expression);
concatPara(expression, subjectType);
split(expression);
concatPara(expression, subjectCode);
split(expression);
concatPara(expression, year);
split(expression);
concatPara(expression, period);
end(expression);
return expression.toString();
}
private StringBuilder begin(StringBuilder expression) {
return expression.append("RSUMIF(");
}
private StringBuilder beginQMYE(StringBuilder expression) {
return expression.append("QMYE(");
}
private StringBuilder end(StringBuilder expression) {
return expression.append(")");
}
......@@ -78,7 +97,10 @@ public class RSUMIFParasBo {
private StringBuilder concatPara(StringBuilder expression, Integer para) {
return expression.append(para);
}
public RSUMIFParasBo(){}
public RSUMIFParasBo() {
}
public RSUMIFParasBo(RSUMIFParasBo otherBo, int period, int curYear) {
this.reportCode = otherBo.reportCode;
this.columnIndex = otherBo.getColumnIndex();
......
......@@ -70,6 +70,20 @@ public class ReportCellTableSUMIFDataSourceDto extends DataSourceDto {
this.name = DataSourceName.ReportDataSource;
}
public void insertQMYEData(OperationEvaluationContext o, FormulaContext formulaContext) {
this.tag = "QMYE";
this.rowIndex = o.getRowIndex();
this.columnIndex = o.getColumnIndex();
this.cellTemplateId = null;
this.period = formulaContext.getPeriod();
this.reportTemplateId = formulaContext.getReportTemplateGroupId().toString();
this.year = formulaContext.getYear();
this.isOnlyManualInput = false;
this.reportName = formulaContext.getReportTemplateGroupId().toString();
this.name = DataSourceName.ReportDataSource;
}
public String getTag() {
return this.tag;
......
......@@ -61,7 +61,7 @@ import static pwc.taxtech.atms.dto.vatdto.WrapPeriodJobDto.*;
public class CitReportServiceImpl extends BaseService {
private final static Logger logger = LoggerFactory.getLogger(CitReportServiceImpl.class);
private final static String[] functions = {"SGSR", "FSJZ", "ND", "BB", "XXFP", "GZSD", "PC", "JXFPMX",
"JXFP", "PSUM", "DFFS", "JFFS", "WPSR", "WPNAME", "WPTYPE", "SUM2", "RSUMIF", "SUM", "QMYE"};
"JXFP", "PSUM", "DFFS", "JFFS", "WPSR", "WPNAME", "WPTYPE", "SUM2", "RSUMIF", "QMYE"};
@Autowired
private OrganizationServiceTemplateGroupMapper orgServiceTemplateGroupMapper;
......
......@@ -10,6 +10,7 @@ import pwc.taxtech.atms.common.util.StringUtil;
import pwc.taxtech.atms.constant.enums.EnumServiceType;
import pwc.taxtech.atms.dao.CitTbamMapper;
import pwc.taxtech.atms.dao.FormulaAdminMapper;
import pwc.taxtech.atms.dao.ProjectMapper;
import pwc.taxtech.atms.dao.ProjectServiceTypeMapper;
import pwc.taxtech.atms.dpo.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dpo.GroupId;
......@@ -43,6 +44,8 @@ public class FormulaAgent {
private PeriodDataSourceMapper periodDataSourceMapper;
@Autowired
private CitTbamMapper citTbamMapper;
@Autowired
private ProjectMapper projectMapper;
public List<CellTemplatePerGroupDto> getCellTemplateGroupDto(Long templateGroupId, String projectId, String code, Integer rowIndex, Integer columnIndex, Integer period) {
return adminMp.getCellTemplatePerGroupDto(templateGroupId, code, rowIndex, columnIndex, projectId, period);
......@@ -266,9 +269,10 @@ public class FormulaAgent {
* @param formulaContext
* @return
*/
public BigDecimal getQMYE(String subjectType, String subjectCode, Integer year, Integer period, FormulaContext formulaContext){
public BigDecimal getQMYE(Integer subjectType, String subjectCode, Integer year, Integer period, FormulaContext formulaContext){
Project project = projectMapper.selectByPrimaryKey(formulaContext.getProjectId());
CitTbamExample citTbamExample = new CitTbamExample();
citTbamExample.createCriteria().andAccountCodeEqualTo(subjectCode).andPeriodEqualTo(year+ CitCommonUtil.getPeriod());
citTbamExample.createCriteria().andAccountCodeEqualTo(subjectCode).andPeriodEqualTo(year+ project.getYear());
List<CitTbam> citTbams = citTbamMapper.selectByExample(citTbamExample);
if(citTbams == null || citTbams.isEmpty()){
return new BigDecimal(0.0);
......
......@@ -529,11 +529,25 @@ public class ReportGeneratorImpl {
* @param workbook 工作簿
*/
public void addFunctionsAndContext(Workbook workbook, String[] functions, FormulaContext formulaContext) {
FreeRefFunction[] functionImpls = {new SGSR(formulaContext), new FSJZ(formulaContext), new ND(formulaContext),
new BB(formulaContext), new XXFP(formulaContext), new GZSD(formulaContext), new PC(formulaContext)
, new JXFPMX(formulaContext), new JXFP(formulaContext), new PSUM(formulaContext), new DFFS(formulaContext),
new JFFS(formulaContext), new WPSR(formulaContext), new WPNAME(formulaContext), new WPTYPE(formulaContext), new SUM2(formulaContext), new RSUMIF(formulaContext), new SUM(formulaContext)};
UDFFinder udfs = new DefaultUDFFinder(functions, functionImpls);
UDFFinder udfToolpack = new AggregatingUDFFinder(udfs);
workbook.addToolPack(udfToolpack);
}
/**
* 注册所有的自定义方法到工作簿
*
* @param workbook 工作簿
*/
public void addCitFunctionsAndContext(Workbook workbook, String[] functions, FormulaContext formulaContext) {
FreeRefFunction[] functionImpls = {new SGSR(formulaContext), new FSJZ(formulaContext), new ND(formulaContext),
new BB(formulaContext), new XXFP(formulaContext), new GZSD(formulaContext), new PC(formulaContext)
, new JXFPMX(formulaContext), new JXFP(formulaContext), new PSUM(formulaContext), new DFFS(formulaContext),
new JFFS(formulaContext), new WPSR(formulaContext), new WPNAME(formulaContext), new WPTYPE(formulaContext),
new SUM2(formulaContext), new RSUMIF(formulaContext), new SUM(formulaContext), new QMYE(formulaContext)};
new SUM2(formulaContext), new RSUMIF(formulaContext), new QMYE(formulaContext)};
UDFFinder udfs = new DefaultUDFFinder(functions, functionImpls);
UDFFinder udfToolpack = new AggregatingUDFFinder(udfs);
workbook.addToolPack(udfToolpack);
......
......@@ -64,7 +64,7 @@ public class ReportServiceImpl extends BaseService {
private final static Logger logger = LoggerFactory.getLogger(ReportServiceImpl.class);
private BlockingQueue<PeriodJob> queue = new LinkedBlockingQueue<>();
private final static String[] functions = {"SGSR", "FSJZ", "ND", "BB", "XXFP", "GZSD", "PC", "JXFPMX",
"JXFP", "PSUM", "DFFS", "JFFS", "WPSR", "WPNAME", "WPTYPE", "SUM2", "RSUMIF", "SUM", "QMYE"};
"JXFP", "PSUM", "DFFS", "JFFS", "WPSR", "WPNAME", "WPTYPE", "SUM2", "RSUMIF", "SUM"};
@Autowired
private ReportGeneratorImpl reportGenerator;
......
......@@ -37,7 +37,7 @@ public class QMYE extends FunctionBase implements FreeRefFunction {
@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
//科目类型
String subjectType = "";
Integer subjectType = 0;
//科目代码
String subjectCode = "";
Integer period = 0;
......@@ -52,7 +52,7 @@ public class QMYE extends FunctionBase implements FreeRefFunction {
dataSource.add(reportCellTableSUMIFDataSourceDto);
try {
//科目类型,固定写为企业科目
subjectType = resolverString(args, ec, 0);
subjectType = resolverInteger(args, ec, 0);
//科目代码
subjectCode = resolverString(args, ec, 1);
year = resolverInteger(args, ec, 2);//年份
......@@ -63,12 +63,6 @@ public class QMYE extends FunctionBase implements FreeRefFunction {
e.printStackTrace();
return new NumberEval(0.00);
} finally {
boolean boo;
if(TableRule.map.get(tableName).substring(0, 3).equals("cit")){
boo = true;
}else{
boo = false;
}
Long dataSourceId = null;
try {
dataSourceId = saveDataRSUMIFSource(ec, dataSource, FormulaDataSourceDetailType.ReportCellTableSUMIFDataSourceDto,
......@@ -80,7 +74,7 @@ public class QMYE extends FunctionBase implements FreeRefFunction {
}
try {
saveFormulaBlock(formulaContext.getPeriod(), ec,
new RSUMIFParasBo().getExpression(args, ec), cellValue, dataSourceId, formulaContext.getProjectId());
new RSUMIFParasBo().getQMYEExpression(subjectType, subjectCode, year, period, ec), cellValue, dataSourceId, formulaContext.getProjectId());
} catch (EvaluationException e) {
e.printStackTrace();
}
......
......@@ -25,10 +25,26 @@ public class SUM extends FunctionBase implements FreeRefFunction {
super(formulaContext);
}
@Override
public ValueEval evaluate(ValueEval[] valueEvals, OperationEvaluationContext operationEvaluationContext) {
for (int i = 0, j = valueEvals.length; i < j; i++) {
try {
return new NumberEval(sum(getData(parameter(resolverString(valueEvals, operationEvaluationContext, i)))).doubleValue());
} catch (EvaluationException e) {
e.printStackTrace();
return defaultEval;
}
}
return defaultEval;
}
//检查参数合法性
public String parameter(String parameter) {
if (parameter.length() != 2)
if (parameter.length() != 2){
throw Exceptions.parameterError;
}
return parameter;
}
......@@ -47,17 +63,4 @@ public class SUM extends FunctionBase implements FreeRefFunction {
return cellValue;
}
@Override
public ValueEval evaluate(ValueEval[] valueEvals, OperationEvaluationContext operationEvaluationContext) {
for (int i = 0, j = valueEvals.length; i < j; i++) {
try {
return new NumberEval(sum(getData(parameter(resolverString(valueEvals, operationEvaluationContext, i)))).doubleValue());
} catch (EvaluationException e) {
e.printStackTrace();
return defaultEval;
}
}
return defaultEval;
}
}
......@@ -559,7 +559,7 @@
if (!_.isEmpty(parsedFormula)) {
debugger;
parsedFormula = 'IFERROR(' + parsedFormula + ', "")';
// parsedFormula = 'IFERROR(' + parsedFormula + ', "")';
sheet.setFormula(data.rowIndex, data.columnIndex, '=' + parsedFormula);
// sheet.setValue(data.rowIndex, data.columnIndex, data.value);
ifShowParseFloat = false; // 有公式或手工数据源,单元格设置为公式
......
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