Commit e3c6ed6c authored by chase's avatar chase

修改bpm公式

parent a30927ca
...@@ -20,7 +20,7 @@ import java.util.List; ...@@ -20,7 +20,7 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* 根据报表项目与科目映射取出科目代码,再通过入参进行TB表数据计算 * 根据报表项目与科目映射取出科目代码,再通过入参进行TB表数据计算
*/ */
public class TBM extends FunctionBase implements FreeRefFunction { public class TBM extends FunctionBase implements FreeRefFunction {
public TBM(FormulaContext formulaContext) { public TBM(FormulaContext formulaContext) {
...@@ -37,21 +37,22 @@ public class TBM extends FunctionBase implements FreeRefFunction { ...@@ -37,21 +37,22 @@ public class TBM extends FunctionBase implements FreeRefFunction {
String mappingName = getStringParam(args[1], ec);//映射名称 String mappingName = getStringParam(args[1], ec);//映射名称
int calculateType = getIntParam(args[2], ec);//计算类型,当取利润时候,1:贷方-借方,2:借方-贷方。当取资产时,1:正数,2:负数 int calculateType = getIntParam(args[2], ec);//计算类型,当取利润时候,1:贷方-借方,2:借方-贷方。当取资产时,1:正数,2:负数
int sourceDataType = getIntParam(args[3], ec);//取值数据源 int sourceDataType = getIntParam(args[3], ec);//取值数据源
String formulaExpression = "TBM(" + evenType + ",\""+mappingName+ "\","+calculateType+","+sourceDataType+ ")"; String formulaExpression = "TBM(" + evenType + ",\"" + mappingName + "\"," + calculateType + "," + sourceDataType + ")";
List<ReportCellDataSourceDto> dataSource = Lists.newArrayList(); List<ReportCellDataSourceDto> dataSource = Lists.newArrayList();
List<String> segment3List = getSegment3List(evenType,mappingName); List<String> segment3List = getSegment3List(evenType, mappingName);
if(CollectionUtils.isEmpty(segment3List)){
if (CollectionUtils.isEmpty(segment3List)) {
return NumberEval.ZERO; return NumberEval.ZERO;
} }
double result = 0.00; double result = 0.00;
if (sourceDataType == 1) { if (sourceDataType == 1) {
result = countForTrialBalance(evenType,calculateType,segment3List,dataSource,formulaContext.getPeriod(),formulaContext.getYear(),formulaContext.getOrganizationId()); result = countForTrialBalance(evenType, calculateType, segment3List, dataSource, formulaContext.getPeriod(), formulaContext.getYear(), formulaContext.getOrganizationId());
} else if (sourceDataType == 2) { } else if (sourceDataType == 2) {
result = countForAdjBalance(evenType,calculateType,segment3List,dataSource,formulaContext.getPeriod(),formulaContext.getYear(),formulaContext.getOrganizationId()); result = countForAdjBalance(evenType, calculateType, segment3List, dataSource, formulaContext.getPeriod(), formulaContext.getYear(), formulaContext.getOrganizationId());
} else if (sourceDataType == 3) { } else if (sourceDataType == 3) {
result = countForTrialFinalBalance(evenType,calculateType,segment3List,dataSource,formulaContext.getPeriod(),formulaContext.getYear(),formulaContext.getOrganizationId()); result = countForTrialFinalBalance(evenType, calculateType, segment3List, dataSource, formulaContext.getPeriod(), formulaContext.getYear(), formulaContext.getOrganizationId());
} else { } else {
return NumberEval.ZERO; return NumberEval.ZERO;
} }
...@@ -63,11 +64,11 @@ public class TBM extends FunctionBase implements FreeRefFunction { ...@@ -63,11 +64,11 @@ public class TBM extends FunctionBase implements FreeRefFunction {
} }
public List<String> getSegment3List(int eventType,String mappingName){ public List<String> getSegment3List(int eventType, String mappingName) {
TrialBalanceMappingExample example = new TrialBalanceMappingExample(); TrialBalanceMappingExample example = new TrialBalanceMappingExample();
if(eventType == 1){ if (eventType == 1) {
example.createCriteria().andPlTypeEqualTo(mappingName); example.createCriteria().andPlTypeEqualTo(mappingName);
}else if(eventType == 2){ } else if (eventType == 2) {
example.createCriteria().andBsTypeEqualTo(mappingName); example.createCriteria().andBsTypeEqualTo(mappingName);
} }
List<TrialBalanceMapping> dataList = SpringContextUtil.trialBalanceMappingMapper.selectByExample(example); List<TrialBalanceMapping> dataList = SpringContextUtil.trialBalanceMappingMapper.selectByExample(example);
...@@ -75,14 +76,25 @@ public class TBM extends FunctionBase implements FreeRefFunction { ...@@ -75,14 +76,25 @@ public class TBM extends FunctionBase implements FreeRefFunction {
.map(o -> o.getSegment3()).collect(Collectors.toList()); .map(o -> o.getSegment3()).collect(Collectors.toList());
} }
private int pardePeriod(int period, int year) { private int parsePeriod(int period, int year) {
return Integer.parseInt("" + year + (period > 9 ? period : ("0" + period))); return Integer.parseInt("" + year + (period > 9 ? period : ("0" + period)));
} }
private double countForTrialBalance(int eventType,int calculateType,List<String> segment3List, List<ReportCellDataSourceDto> contain, int period, int year, String orgId) {
private int parseLastPeriod(int period, int year) {
if (period == 1) {
period = 12;
year -= 1;
} else {
period -= 1;
}
return Integer.parseInt("" + year + (period > 9 ? period : ("0" + period)));
}
private double countForTrialBalance(int eventType, int calculateType, List<String> segment3List, List<ReportCellDataSourceDto> contain, int period, int year, String orgId) {
Organization organization = SpringContextUtil.organizationMapper.selectByPrimaryKey(orgId); Organization organization = SpringContextUtil.organizationMapper.selectByPrimaryKey(orgId);
TrialBalanceExample glBalanceExample = new TrialBalanceExample(); TrialBalanceExample glBalanceExample = new TrialBalanceExample();
TrialBalanceExample.Criteria c1 = glBalanceExample.createCriteria().andSegment3In(segment3List) TrialBalanceExample.Criteria c1 = glBalanceExample.createCriteria().andSegment3In(segment3List)
.andPeriodEqualTo(pardePeriod(period, year)); .andPeriodEqualTo(parsePeriod(period, year));
if (organization != null) { if (organization != null) {
c1.andOrganizationIdEqualTo(organization.getId()); c1.andOrganizationIdEqualTo(organization.getId());
} }
...@@ -93,20 +105,20 @@ public class TBM extends FunctionBase implements FreeRefFunction { ...@@ -93,20 +105,20 @@ public class TBM extends FunctionBase implements FreeRefFunction {
BigDecimal amount = new BigDecimal(0); BigDecimal amount = new BigDecimal(0);
for (TrialBalance balance : list) { for (TrialBalance balance : list) {
ReportCellDataSourceDto dto = new ReportCellDataSourceDto(); ReportCellDataSourceDto dto = new ReportCellDataSourceDto();
if(eventType == 1 ){ if (eventType == 1) {
if(calculateType == 1){ if (calculateType == 1) {
dto.setAmount(balance.getPeriodCrBeq().subtract(balance.getPeriodDrBeq())); dto.setAmount(balance.getPeriodCrBeq().subtract(balance.getPeriodDrBeq()));
}else if(calculateType == 2){ } else if (calculateType == 2) {
dto.setAmount(balance.getPeriodDrBeq().subtract(balance.getPeriodCrBeq())); dto.setAmount(balance.getPeriodDrBeq().subtract(balance.getPeriodCrBeq()));
} }
}else if(eventType == 2){ } else if (eventType == 2) {
if(calculateType == 1){ if (calculateType == 1) {
dto.setAmount(balance.getEndBalBeq()); dto.setAmount(balance.getEndBalBeq());
}else if(calculateType == 2){ } else if (calculateType == 2) {
dto.setAmount(balance.getEndBalBeq().multiply(new BigDecimal(-1))); dto.setAmount(balance.getEndBalBeq().multiply(new BigDecimal(-1)));
} }
} }
amount = amount.add(dto.getAmount()==null?(new BigDecimal(0)):dto.getAmount()); amount = amount.add(dto.getAmount() == null ? (new BigDecimal(0)) : dto.getAmount());
dto.setPeriod(period); dto.setPeriod(period);
dto.setIsOnlyManualInput(Boolean.FALSE); dto.setIsOnlyManualInput(Boolean.FALSE);
dto.setName(Constant.DataSourceName.ReportDataSource); dto.setName(Constant.DataSourceName.ReportDataSource);
...@@ -116,11 +128,11 @@ public class TBM extends FunctionBase implements FreeRefFunction { ...@@ -116,11 +128,11 @@ public class TBM extends FunctionBase implements FreeRefFunction {
return amount.doubleValue(); return amount.doubleValue();
} }
private double countForAdjBalance(int eventType,int calculateType,List<String> segment3List, List<ReportCellDataSourceDto> contain, int period, int year, String orgId) { private double countForAdjBalance(int eventType, int calculateType, List<String> segment3List, List<ReportCellDataSourceDto> contain, int period, int year, String orgId) {
Organization organization = SpringContextUtil.organizationMapper.selectByPrimaryKey(orgId); Organization organization = SpringContextUtil.organizationMapper.selectByPrimaryKey(orgId);
AdjustmentTableExample glBalanceExample = new AdjustmentTableExample(); AdjustmentTableExample glBalanceExample = new AdjustmentTableExample();
AdjustmentTableExample.Criteria c1 = glBalanceExample.createCriteria().andSegment3In(segment3List) AdjustmentTableExample.Criteria c1 = glBalanceExample.createCriteria().andSegment3In(segment3List)
.andPeriodEqualTo(pardePeriod(period, year)); .andPeriodEqualTo(parsePeriod(period, year));
if (organization != null) { if (organization != null) {
c1.andOrganizationIdEqualTo(organization.getId()); c1.andOrganizationIdEqualTo(organization.getId());
} }
...@@ -129,36 +141,71 @@ public class TBM extends FunctionBase implements FreeRefFunction { ...@@ -129,36 +141,71 @@ public class TBM extends FunctionBase implements FreeRefFunction {
return 0.0; return 0.0;
} }
BigDecimal amount = new BigDecimal(0); BigDecimal amount = new BigDecimal(0);
//计算本期发生
for (AdjustmentTable balance : list) { for (AdjustmentTable balance : list) {
ReportCellDataSourceDto dto = new ReportCellDataSourceDto(); ReportCellDataSourceDto dto = new ReportCellDataSourceDto();
if(eventType == 1 ){ if (eventType == 1) {
if(calculateType == 1){ if (calculateType == 1) {
dto.setAmount(balance.getPeriodCrBeq().subtract(balance.getPeriodDrBeq())); dto.setAmount(balance.getPeriodCrBeq().subtract(balance.getPeriodDrBeq()));
}else if(calculateType == 2){ } else if (calculateType == 2) {
dto.setAmount(balance.getPeriodDrBeq().subtract(balance.getPeriodCrBeq())); dto.setAmount(balance.getPeriodDrBeq().subtract(balance.getPeriodCrBeq()));
} }
}else if(eventType == 2){ } else if (eventType == 2) {
if(calculateType == 1){ if (calculateType == 1) {
dto.setAmount(balance.getEndBalBeq()); dto.setAmount(balance.getEndBalBeq());
}else if(calculateType == 2){ } else if (calculateType == 2) {
dto.setAmount(balance.getEndBalBeq().multiply(new BigDecimal(-1))); dto.setAmount(balance.getEndBalBeq().multiply(new BigDecimal(-1)));
} }
} }
amount = amount.add(dto.getAmount()==null?(new BigDecimal(0)):dto.getAmount()); amount = amount.add(dto.getAmount() == null ? (new BigDecimal(0)) : dto.getAmount());
dto.setPeriod(period); dto.setPeriod(period);
dto.setIsOnlyManualInput(Boolean.FALSE); dto.setIsOnlyManualInput(Boolean.FALSE);
dto.setName(Constant.DataSourceName.ReportDataSource); dto.setName(Constant.DataSourceName.ReportDataSource);
dto.setType(FormulaDataSourceType.TrialBalanceSource.getCode()); dto.setType(FormulaDataSourceType.TrialBalanceSource.getCode());
contain.add(dto); contain.add(dto);
} }
//计算往期发生
glBalanceExample = new AdjustmentTableExample();
c1 = glBalanceExample.createCriteria().andSegment3In(segment3List)
.andPeriodEqualTo(parseLastPeriod(period, year));
if (organization != null) {
c1.andOrganizationIdEqualTo(organization.getId());
}
list = SpringContextUtil.adjustmentTableMapper.selectByExample(glBalanceExample);
if (CollectionUtils.isNotEmpty(list)) {
BigDecimal lastAmount = new BigDecimal(0);
for (AdjustmentTable balance : list) {
ReportCellDataSourceDto dto = new ReportCellDataSourceDto();
if (eventType == 1) {
if (calculateType == 1) {
dto.setAmount(balance.getPeriodCrBeq().subtract(balance.getPeriodDrBeq()));
} else if (calculateType == 2) {
dto.setAmount(balance.getPeriodDrBeq().subtract(balance.getPeriodCrBeq()));
}
} else if (eventType == 2) {
if (calculateType == 1) {
dto.setAmount(balance.getEndBalBeq());
} else if (calculateType == 2) {
dto.setAmount(balance.getEndBalBeq().multiply(new BigDecimal(-1)));
}
}
lastAmount = lastAmount.add(dto.getAmount() == null ? (new BigDecimal(0)) : dto.getAmount());
dto.setPeriod(period);
dto.setIsOnlyManualInput(Boolean.FALSE);
dto.setName(Constant.DataSourceName.ReportDataSource);
dto.setType(FormulaDataSourceType.TrialBalanceSource.getCode());
contain.add(dto);
}
return amount.add(lastAmount.multiply(new BigDecimal(-1))).doubleValue();
}
return amount.doubleValue(); return amount.doubleValue();
} }
private double countForTrialFinalBalance(int eventType,int calculateType,List<String> segment3List, List<ReportCellDataSourceDto> contain, int period, int year, String orgId) { private double countForTrialFinalBalance(int eventType, int calculateType, List<String> segment3List, List<ReportCellDataSourceDto> contain, int period, int year, String orgId) {
Organization organization = SpringContextUtil.organizationMapper.selectByPrimaryKey(orgId); Organization organization = SpringContextUtil.organizationMapper.selectByPrimaryKey(orgId);
TrialBalanceFinalExample glBalanceExample = new TrialBalanceFinalExample(); TrialBalanceFinalExample glBalanceExample = new TrialBalanceFinalExample();
TrialBalanceFinalExample.Criteria c1 = glBalanceExample.createCriteria().andSegment3In(segment3List) TrialBalanceFinalExample.Criteria c1 = glBalanceExample.createCriteria().andSegment3In(segment3List)
.andPeriodEqualTo(pardePeriod(period, year)); .andPeriodEqualTo(parsePeriod(period, year));
if (organization != null) { if (organization != null) {
c1.andOrganizationIdEqualTo(organization.getId()); c1.andOrganizationIdEqualTo(organization.getId());
} }
...@@ -169,20 +216,20 @@ public class TBM extends FunctionBase implements FreeRefFunction { ...@@ -169,20 +216,20 @@ public class TBM extends FunctionBase implements FreeRefFunction {
BigDecimal amount = new BigDecimal(0); BigDecimal amount = new BigDecimal(0);
for (TrialBalanceFinal balance : list) { for (TrialBalanceFinal balance : list) {
ReportCellDataSourceDto dto = new ReportCellDataSourceDto(); ReportCellDataSourceDto dto = new ReportCellDataSourceDto();
if(eventType == 1 ){ if (eventType == 1) {
if(calculateType == 1){ if (calculateType == 1) {
dto.setAmount(balance.getPeriodCrBeq().subtract(balance.getPeriodDrBeq())); dto.setAmount(balance.getPeriodCrBeq().subtract(balance.getPeriodDrBeq()));
}else if(calculateType == 2){ } else if (calculateType == 2) {
dto.setAmount(balance.getPeriodDrBeq().subtract(balance.getPeriodCrBeq())); dto.setAmount(balance.getPeriodDrBeq().subtract(balance.getPeriodCrBeq()));
} }
}else if(eventType == 2){ } else if (eventType == 2) {
if(calculateType == 1){ if (calculateType == 1) {
dto.setAmount(balance.getEndBalBeq()); dto.setAmount(balance.getEndBalBeq());
}else if(calculateType == 2){ } else if (calculateType == 2) {
dto.setAmount(balance.getEndBalBeq().multiply(new BigDecimal(-1))); dto.setAmount(balance.getEndBalBeq().multiply(new BigDecimal(-1)));
} }
} }
amount = amount.add(dto.getAmount()==null?(new BigDecimal(0)):dto.getAmount()); amount = amount.add(dto.getAmount() == null ? (new BigDecimal(0)) : dto.getAmount());
dto.setPeriod(period); dto.setPeriod(period);
dto.setIsOnlyManualInput(Boolean.FALSE); dto.setIsOnlyManualInput(Boolean.FALSE);
dto.setName(Constant.DataSourceName.ReportDataSource); dto.setName(Constant.DataSourceName.ReportDataSource);
......
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