Commit b1ffe129 authored by chase's avatar chase

新增公式

parent 86e861e2
......@@ -62,7 +62,7 @@ public class SpringContextUtil implements ApplicationContextAware {
public static RevenueTypeMappingMapper revenueTypeMappingMapper;
public static InvoiceRecordMapper invoiceRecordMapper;
public static CertifiedInvoicesListMapper certifiedInvoicesListMapper;
public static TrialBalanceMappingMapper trialBalanceMappingMapper;
public static CashFlowMapper cashFlowMapper;
......@@ -147,6 +147,7 @@ public class SpringContextUtil implements ApplicationContextAware {
revenueTypeMappingMapper = webApplicationContext.getBean(RevenueTypeMappingMapper.class);
invoiceRecordMapper = webApplicationContext.getBean(InvoiceRecordMapper.class);
certifiedInvoicesListMapper = webApplicationContext.getBean(CertifiedInvoicesListMapper.class);
trialBalanceMappingMapper = webApplicationContext.getBean(TrialBalanceMappingMapper.class);
/* map.put("balance_sheet", balanceMapper);
map.put("profit_loss_statement",profitLossStatementMapper);
map.put("cash_flow", cashFlowMapper);
......
......@@ -596,7 +596,7 @@ public class ReportGeneratorImpl {
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 KPSR(formulaContext)};
new SUM2(formulaContext), new RSUMIF(formulaContext), new SUM(formulaContext),new KPSR(formulaContext),new TBM(formulaContext)};
UDFFinder udfs = new DefaultUDFFinder(functions, functionImpls);
UDFFinder udfToolpack = new AggregatingUDFFinder(udfs);
workbook.addToolPack(udfToolpack);
......
......@@ -67,7 +67,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", "KPSR"};
"JXFP", "PSUM", "DFFS", "JFFS", "WPSR", "WPNAME", "WPTYPE", "SUM2", "RSUMIF", "SUM", "KPSR","TBM"};
@Autowired
private ReportGeneratorImpl reportGenerator;
......
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.SpringContextUtil;
import pwc.taxtech.atms.constant.Constant;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceType;
import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto;
import pwc.taxtech.atms.entity.Organization;
import pwc.taxtech.atms.vat.entity.*;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* 根据报表项目与科目映射取出科目代码,再通过入参进行TB表数据计算
*/
public class TBM extends FunctionBase implements FreeRefFunction {
public TBM(FormulaContext formulaContext) {
super(formulaContext);
}
@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
if (args.length < 4) {
return null;
}
int evenType = getIntParam(args[0], ec);//事件类型,1:利润映射,2:资产映射
String mappingName = getStringParam(args[1], ec);//映射名称
int calculateType = getIntParam(args[2], ec);//计算类型,当取利润时候,1:贷方-借方,2:借方-贷方。当取资产时,1:正数,2:负数
int sourceDataType = getIntParam(args[3], ec);//取值数据源
String formulaExpression = "TBM(" + evenType + ",\""+mappingName+ "\","+calculateType+","+sourceDataType+ ")";
List<ReportCellDataSourceDto> dataSource = Lists.newArrayList();
List<String> segment3List = getSegment3List(evenType,mappingName);
if(CollectionUtils.isEmpty(segment3List)){
return NumberEval.ZERO;
}
double result = 0.00;
if (sourceDataType == 1) {
result = countForTrialBalance(evenType,calculateType,segment3List,dataSource,formulaContext.getPeriod(),formulaContext.getYear(),formulaContext.getOrganizationId());
} else if (sourceDataType == 2) {
result = countForAdjBalance(evenType,calculateType,segment3List,dataSource,formulaContext.getPeriod(),formulaContext.getYear(),formulaContext.getOrganizationId());
} else if (sourceDataType == 3) {
result = countForTrialFinalBalance(evenType,calculateType,segment3List,dataSource,formulaContext.getPeriod(),formulaContext.getYear(),formulaContext.getOrganizationId());
} else {
return NumberEval.ZERO;
}
Long dataSoureId = saveDataSource(ec, Collections.singletonList(dataSource),
FormulaDataSourceDetailType.FormulaDataSourceDto,
new BigDecimal(result), formulaContext.getPeriod(), formulaContext.getReportTemplateGroupId(), formulaContext.getProjectId());
saveFormulaBlock(formulaContext.getPeriod(), ec, formulaExpression, new BigDecimal(result), dataSoureId, formulaContext.getProjectId());
return new NumberEval(result);
}
public List<String> getSegment3List(int eventType,String mappingName){
TrialBalanceMappingExample example = new TrialBalanceMappingExample();
if(eventType == 1){
example.createCriteria().andPlTypeEqualTo(mappingName);
}else if(eventType == 2){
example.createCriteria().andBsTypeEqualTo(mappingName);
}
List<TrialBalanceMapping> dataList = SpringContextUtil.trialBalanceMappingMapper.selectByExample(example);
return dataList.stream()
.map(o -> o.getSegment3()).collect(Collectors.toList());
}
private int pardePeriod(int period, int year) {
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);
TrialBalanceExample glBalanceExample = new TrialBalanceExample();
TrialBalanceExample.Criteria c1 = glBalanceExample.createCriteria().andSegment3In(segment3List)
.andPeriodEqualTo(pardePeriod(period, year));
if (organization != null) {
c1.andOrganizationIdEqualTo(organization.getId());
}
List<TrialBalance> list = SpringContextUtil.trialBalanceMapper.selectByExample(glBalanceExample);
if (CollectionUtils.isEmpty(list)) {
return 0.0;
}
BigDecimal amount = new BigDecimal(0);
for (TrialBalance 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)));
}
}
amount = amount.add(dto.getAmount());
dto.setPeriod(period);
dto.setIsOnlyManualInput(Boolean.FALSE);
dto.setName(Constant.DataSourceName.ReportDataSource);
dto.setType(FormulaDataSourceType.TrialBalanceSource.getCode());
contain.add(dto);
}
return amount.doubleValue();
}
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);
AdjustmentTableExample glBalanceExample = new AdjustmentTableExample();
AdjustmentTableExample.Criteria c1 = glBalanceExample.createCriteria().andSegment3In(segment3List)
.andPeriodEqualTo(pardePeriod(period, year));
if (organization != null) {
c1.andOrganizationIdEqualTo(organization.getId());
}
List<AdjustmentTable> list = SpringContextUtil.adjustmentTableMapper.selectByExample(glBalanceExample);
if (CollectionUtils.isEmpty(list)) {
return 0.0;
}
BigDecimal amount = 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)));
}
}
amount.add(dto.getAmount());
dto.setPeriod(period);
dto.setIsOnlyManualInput(Boolean.FALSE);
dto.setName(Constant.DataSourceName.ReportDataSource);
dto.setType(FormulaDataSourceType.TrialBalanceSource.getCode());
contain.add(dto);
}
return amount.doubleValue();
}
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);
TrialBalanceFinalExample glBalanceExample = new TrialBalanceFinalExample();
TrialBalanceFinalExample.Criteria c1 = glBalanceExample.createCriteria().andSegment3In(segment3List)
.andPeriodEqualTo(pardePeriod(period, year));
if (organization != null) {
c1.andOrganizationIdEqualTo(organization.getId());
}
List<TrialBalanceFinal> list = SpringContextUtil.trialBalanceFinalMapper.selectByExample(glBalanceExample);
if (CollectionUtils.isEmpty(list)) {
return 0.0;
}
BigDecimal amount = new BigDecimal(0);
for (TrialBalanceFinal 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)));
}
}
amount.add(dto.getAmount());
dto.setPeriod(period);
dto.setIsOnlyManualInput(Boolean.FALSE);
dto.setName(Constant.DataSourceName.ReportDataSource);
dto.setType(FormulaDataSourceType.TrialBalanceSource.getCode());
contain.add(dto);
}
return amount.doubleValue();
}
}
package pwc.taxtech.atms.vat.dao;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
import pwc.taxtech.atms.MyVatMapper;
import pwc.taxtech.atms.vat.entity.TrialBalanceMapping;
import pwc.taxtech.atms.vat.entity.TrialBalanceMappingExample;
@Mapper
public interface TrialBalanceMappingMapper extends MyVatMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table trial_balance_mapping
*
* @mbg.generated
*/
long countByExample(TrialBalanceMappingExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table trial_balance_mapping
*
* @mbg.generated
*/
int deleteByExample(TrialBalanceMappingExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table trial_balance_mapping
*
* @mbg.generated
*/
int deleteByPrimaryKey(Long id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table trial_balance_mapping
*
* @mbg.generated
*/
int insert(TrialBalanceMapping record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table trial_balance_mapping
*
* @mbg.generated
*/
int insertSelective(TrialBalanceMapping record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table trial_balance_mapping
*
* @mbg.generated
*/
List<TrialBalanceMapping> selectByExampleWithRowbounds(TrialBalanceMappingExample example, RowBounds rowBounds);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table trial_balance_mapping
*
* @mbg.generated
*/
List<TrialBalanceMapping> selectByExample(TrialBalanceMappingExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table trial_balance_mapping
*
* @mbg.generated
*/
TrialBalanceMapping selectByPrimaryKey(Long id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table trial_balance_mapping
*
* @mbg.generated
*/
int updateByExampleSelective(@Param("record") TrialBalanceMapping record, @Param("example") TrialBalanceMappingExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table trial_balance_mapping
*
* @mbg.generated
*/
int updateByExample(@Param("record") TrialBalanceMapping record, @Param("example") TrialBalanceMappingExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table trial_balance_mapping
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(TrialBalanceMapping record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table trial_balance_mapping
*
* @mbg.generated
*/
int updateByPrimaryKey(TrialBalanceMapping record);
}
\ No newline at end of file
package pwc.taxtech.atms.vat.entity;
import java.io.Serializable;
import pwc.taxtech.atms.entity.BaseEntity;
/**
*
* This class was generated by MyBatis Generator.
* This class corresponds to the database table trial_balance_mapping
*
* @mbg.generated do_not_delete_during_merge
*/
public class TrialBalanceMapping extends BaseEntity implements Serializable {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column trial_balance_mapping.id
*
* @mbg.generated
*/
private Long id;
/**
* Database Column Remarks:
* 科目代码
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column trial_balance_mapping.segment3
*
* @mbg.generated
*/
private String segment3;
/**
* Database Column Remarks:
* 科目名称
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column trial_balance_mapping.segment3_name
*
* @mbg.generated
*/
private String segment3Name;
/**
* Database Column Remarks:
* 资产负债表类型
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column trial_balance_mapping.bs_type
*
* @mbg.generated
*/
private String bsType;
/**
* Database Column Remarks:
* 利润表类型映射
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column trial_balance_mapping.pl_type
*
* @mbg.generated
*/
private String plType;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table trial_balance_mapping
*
* @mbg.generated
*/
private static final long serialVersionUID = 1L;
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column trial_balance_mapping.id
*
* @return the value of trial_balance_mapping.id
*
* @mbg.generated
*/
public Long getId() {
return id;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column trial_balance_mapping.id
*
* @param id the value for trial_balance_mapping.id
*
* @mbg.generated
*/
public void setId(Long id) {
this.id = id;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column trial_balance_mapping.segment3
*
* @return the value of trial_balance_mapping.segment3
*
* @mbg.generated
*/
public String getSegment3() {
return segment3;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column trial_balance_mapping.segment3
*
* @param segment3 the value for trial_balance_mapping.segment3
*
* @mbg.generated
*/
public void setSegment3(String segment3) {
this.segment3 = segment3 == null ? null : segment3.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column trial_balance_mapping.segment3_name
*
* @return the value of trial_balance_mapping.segment3_name
*
* @mbg.generated
*/
public String getSegment3Name() {
return segment3Name;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column trial_balance_mapping.segment3_name
*
* @param segment3Name the value for trial_balance_mapping.segment3_name
*
* @mbg.generated
*/
public void setSegment3Name(String segment3Name) {
this.segment3Name = segment3Name == null ? null : segment3Name.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column trial_balance_mapping.bs_type
*
* @return the value of trial_balance_mapping.bs_type
*
* @mbg.generated
*/
public String getBsType() {
return bsType;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column trial_balance_mapping.bs_type
*
* @param bsType the value for trial_balance_mapping.bs_type
*
* @mbg.generated
*/
public void setBsType(String bsType) {
this.bsType = bsType == null ? null : bsType.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column trial_balance_mapping.pl_type
*
* @return the value of trial_balance_mapping.pl_type
*
* @mbg.generated
*/
public String getPlType() {
return plType;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column trial_balance_mapping.pl_type
*
* @param plType the value for trial_balance_mapping.pl_type
*
* @mbg.generated
*/
public void setPlType(String plType) {
this.plType = plType == null ? null : plType.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table trial_balance_mapping
*
* @mbg.generated
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", segment3=").append(segment3);
sb.append(", segment3Name=").append(segment3Name);
sb.append(", bsType=").append(bsType);
sb.append(", plType=").append(plType);
sb.append("]");
return sb.toString();
}
}
\ No newline at end of file
......@@ -703,16 +703,16 @@
if ($scope.detail.dataGridSource && $scope.detail.dataGridSource.length > 0) {
//判断是否是动态生成sheet
if(new Number($scope.detail.cellTemplateId)<0){
$("#dataGridFooterSummary").html("");
}else{
evalVal = _.reduce($scope.detail.dataGridSource, function (memo, x) {
return memo + x.cellValue;
}, 0);
$("#dataGridFooterSummary").html($translate.instant('Conclusion') +
'&nbsp;&nbsp;&nbsp;&nbsp;' + evalVal.formatAmount(precition));
}
// if(new Number($scope.detail.cellTemplateId)<0){
// $("#dataGridFooterSummary").html("");
// }else{
// evalVal = _.reduce($scope.detail.dataGridSource, function (memo, x) {
// return memo + x.cellValue;
// }, 0);
// $("#dataGridFooterSummary").html($translate.instant('Conclusion') +
// '&nbsp;&nbsp;&nbsp;&nbsp;' + evalVal.formatAmount(precition));
// }
$("#dataGridFooterSummary").html("");
}
......
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