Commit 4124b3b9 authored by zhkwei's avatar zhkwei

CIT期末余额公式

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