Commit cb7ce216 authored by sherlock's avatar sherlock

DFFS cell value

parent 59f49ed5
package pwc.taxtech.atms.vat.service.impl.report.functions;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
import pwc.taxtech.atms.common.util.DateUtils;
import pwc.taxtech.atms.common.util.MyAsserts;
import pwc.taxtech.atms.common.util.SpringContextUtil;
import pwc.taxtech.atms.constant.Constant;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.dpo.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto;
import pwc.taxtech.atms.entity.AccountMapping;
import pwc.taxtech.atms.entity.AccountMappingExample;
import pwc.taxtech.atms.entity.EnterpriseAccountSetOrg;
import pwc.taxtech.atms.entity.EnterpriseAccountSetOrgExample;
import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.vat.entity.GlBalance;
import pwc.taxtech.atms.vat.entity.GlBalanceExample;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
......@@ -34,7 +43,7 @@ public class DFFS extends FunctionBase implements FreeRefFunction {
int year = getIntParam(args[2], ec);
int period = getIntParam(args[3], ec);
String formulaExpression = "DFFS(" + type + "," + code + ","
String formulaExpression = "DFFS(" + type + ",\"" + code + "\","
+ year + "," + period + ")";
logger.debug(formulaExpression);
......@@ -46,7 +55,7 @@ public class DFFS extends FunctionBase implements FreeRefFunction {
year = year + yearOffset;
Date date = DateUtils.strToDate(year + "-" + period + "-" + 15);
List<GlBalance> list;
List<ReportCellDataSourceDto> dataSource = Lists.newArrayList();
if(type == 0){
EnterpriseAccountSetOrgExample example = new EnterpriseAccountSetOrgExample();
example.createCriteria().andEffectiveDateLessThanOrEqualTo(date).andExpiredDateGreaterThanOrEqualTo(date).andOrganizationIdEqualTo(orgId);
......@@ -58,18 +67,30 @@ public class DFFS extends FunctionBase implements FreeRefFunction {
accountMappingExample.createCriteria().andOrganizationIdEqualTo(orgId).andEnterpriseAccountSetIdEqualTo(enterpriseAccountSetOrgs.get(0).getEnterpriseAccountSetId());
List<AccountMapping> accountMappings = SpringContextUtil.accountMappingMapper.selectByExample(accountMappingExample);
double result = 0;
for(AccountMapping a : accountMappings){
result += count(a.getEnterpriseAccountCode());
result += count(a.getEnterpriseAccountCode(), dataSource, period);
}
Long dataSoureId = saveDataSource(ec, Collections.singletonList(dataSource),
FormulaDataSourceDetailType.FormulaDataSourceDto,
new BigDecimal(result), period, formulaContext.getReportTemplateGroupId(), formulaContext.getProjectId());
saveFormulaBlock(period, ec, formulaExpression, new BigDecimal(result), dataSoureId, formulaContext.getProjectId());
return new NumberEval(result);
} else if(type == 1){
return new NumberEval(count(code));
double result = count(code, dataSource, period);
Long dataSoureId = saveDataSource(ec, Collections.singletonList(dataSource),
FormulaDataSourceDetailType.FormulaDataSourceDto,
new BigDecimal(result), period, formulaContext.getReportTemplateGroupId(), formulaContext.getProjectId());
saveFormulaBlock(period, ec, formulaExpression, new BigDecimal(result), dataSoureId, formulaContext.getProjectId());
return new NumberEval(result);
}
return NumberEval.ZERO;
}
private double count(String code){
private double count(String code, List<ReportCellDataSourceDto> contain, int period){
GlBalanceExample glBalanceExample = new GlBalanceExample();
GlBalanceExample.Criteria c1 = glBalanceExample.createCriteria().andSegment3EqualTo(code);
GlBalanceExample.Criteria c2 = glBalanceExample.createCriteria().andSegment4EqualTo(code);
......@@ -82,6 +103,15 @@ public class DFFS extends FunctionBase implements FreeRefFunction {
if(CollectionUtils.isEmpty(temp)){
temp = list;
}
for(GlBalance glBalance : temp){
ReportCellDataSourceDto dto = new ReportCellDataSourceDto();
dto.setAmount(glBalance.getPtdCr());
dto.setPeriod(period);
dto.setIsOnlyManualInput(Boolean.FALSE);
dto.setName(Constant.DataSourceName.ReportDataSource);
contain.add(dto);
}
return temp.stream().mapToDouble(a -> a.getPtdCr().doubleValue()).sum();
}
}
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