Commit 0f67a6e0 authored by frank.xa.zhang's avatar frank.xa.zhang

finished fsjz function

parent aa8e1c62
package pwc.taxtech.atms.constant.enums;
public enum FormulaDataSourceDetailType {
BSPLFormulaDataSourceDto(1, pwc.taxtech.atms.dto.vatdto.BSPLFormulaDataSourceDto.class);
private Integer code;
private Class clas;
FormulaDataSourceDetailType(Integer code,Class clas) {
this.code = code;this.clas = clas;
}
public Integer getCode() {
return code;
}
public Class getClas(){return clas;}
}
package pwc.taxtech.atms.constant.enums;
public enum KeyValueConfigResultType {
Accounting(1),
Percentage(2),
Boolean (3),
String (4),
Integer (5);
private Integer code;
KeyValueConfigResultType(Integer code) {
this.code = code;
}
public Integer getCode() {
return code;
}
}
......@@ -32,7 +32,7 @@ public interface FormulaAdminMapper extends MyMapper {
"WHERE " +
" cell_template_config.data_source_type = 1 " +
" AND template.template_group_id = #{groupId}")
List<CellTemplatePerGroupDto> getCellTemplatePerGroupDto(@Param("groupId") String groupId);
List<CellTemplatePerGroupDto> getCellTemplatePerGroupDto(@Param("groupId") Long groupId);
@Select("SELECT " +
......
package pwc.taxtech.atms.dao.dao;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.dao.ProjectMapper;
import pwc.taxtech.atms.entitiy.Project;
import pwc.taxtech.atms.entitiy.ProjectExample;
@Service
public class ProjectDao {
@Autowired
ProjectMapper projectMapper;
public String getDbNameWithYearAndOrgID(String orgID,int year){
ProjectExample example = new ProjectExample();
example.createCriteria().andOrganizationIDEqualTo(orgID).andYearEqualTo(year);
Project project = projectMapper.selectByExample(example).get(0);
String dbName = StringUtils.EMPTY;
if (project != null) {
dbName = project.getDbName();
}
return dbName;
}
}
package pwc.taxtech.atms.dto;
public class GroupId {
public String groupId;
public Long groupId;
public Integer isDefault;
}
......@@ -108,5 +108,9 @@ public interface BalanceMapper extends MyVatMapper {
*/
int updateByPrimaryKey(Balance record);
BigDecimal getSumOfBalance(@Param("acctCode") String acctCode,@Param("direction") int direction);
BigDecimal getSumOfBalance(@Param("acctCode") String acctCode,@Param("direction") int direction,@Param("period") int period);
BigDecimal getFirstOfBalance(@Param("acctCode") String acctCode,@Param("direction") int direction,@Param("period") int period);
Balance getFirstWithDbNameAndAccountCodeAndPeriod(@Param("dbName") String dbName,@Param("accountCode") String accountCode,@Param("period") int period);
}
\ No newline at end of file
package pwc.taxtech.atms.vat.dao;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
......@@ -107,4 +109,6 @@ public interface PeriodCellTemplateMapper extends MyVatMapper {
int updateByPrimaryKey(PeriodCellTemplate record);
void batchInsert(List<PeriodCellTemplate> list);
Long getCellTemplateIDWithMap(@Param("map") Map<String,Object> map);
}
\ No newline at end of file
......@@ -110,5 +110,5 @@ public interface PeriodTemplateMapper extends MyVatMapper {
void batchInsert(List<PeriodTemplate> periodTemplateList);
List<CellTemplatePerGroupDto> getCellTemplatePerGroup(Integer period,String reportTemplateGroupID);
List<CellTemplatePerGroupDto> getCellTemplatePerGroup(@Param("period") Integer period,@Param("reportTemplateGroupID")Long reportTemplateGroupID);
}
\ No newline at end of file
package pwc.taxtech.atms.vat.dao.dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.vat.dao.VatEnterpriseAccountMapper;
import pwc.taxtech.atms.vat.entity.VatEnterpriseAccount;
import pwc.taxtech.atms.vat.entity.VatEnterpriseAccountExample;
import java.util.List;
@Service
public class VatEnterpriseAccountDao {
@Autowired
VatEnterpriseAccountMapper vatEnterpriseAccountMapper;
public List<VatEnterpriseAccount> getListByAccountCode(String accountCode) {
VatEnterpriseAccountExample example = new VatEnterpriseAccountExample();
example.createCriteria().andAcctCodeEqualTo(accountCode);
return vatEnterpriseAccountMapper.selectByExample(example);
}
}
......@@ -18,6 +18,7 @@ import pwc.taxtech.atms.service.impl.DistributedIDService;
import pwc.taxtech.atms.vat.dao.*;
import pwc.taxtech.atms.vat.entity.*;
import pwc.taxtech.atms.vat.service.ReportGenerator;
import pwc.taxtech.atms.vat.service.impl.report.functions.FSJZ;
import pwc.taxtech.atms.vat.service.impl.report.functions.FormulaAgent;
import pwc.taxtech.atms.vat.service.impl.report.functions.FormulaContext;
import pwc.taxtech.atms.vat.service.impl.report.functions.SGSR;
......@@ -72,6 +73,11 @@ public class ReportGeneratorImpl implements ReportGenerator {
if (workbook != null) {
Workbook newWorkbook = workbook.get();
addFunctionsToWorkbook(newWorkbook);
int sheetCount = newWorkbook.getNumberOfSheets();
for (int i = 0; i < sheetCount; i++) {
......@@ -226,10 +232,10 @@ public class ReportGeneratorImpl implements ReportGenerator {
* @param workbook 工作簿
*/
private void addFunctionsToWorkbook(Workbook workbook) {
String[] functionNames = {"SGSR"};
String[] functionNames = {"SGSR","FSJZ"};
FormulaContext formulaContext = new FormulaContext();
formulaContext.setFormulaAgent(formulaAgent);
FreeRefFunction[] functionImpls = {new SGSR(formulaContext)};
FreeRefFunction[] functionImpls = {new SGSR(formulaContext),new FSJZ(formulaContext)};
UDFFinder udfs = new DefaultUDFFinder(functionNames, functionImpls);
UDFFinder udfToolpack = new AggregatingUDFFinder(udfs);
workbook.addToolPack(udfToolpack);
......
......@@ -4,8 +4,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import pwc.taxtech.atms.dao.*;
import pwc.taxtech.atms.dao.dao.ProjectDao;
import pwc.taxtech.atms.service.impl.DistributedIDService;
import pwc.taxtech.atms.vat.dao.*;
import pwc.taxtech.atms.vat.dao.dao.VatEnterpriseAccountDao;
import pwc.taxtech.atms.vat.entity.PeriodFormulaBlock;
import pwc.taxtech.atms.vat.service.ReportGenerator;
public class VatAbstractService {
......@@ -44,6 +47,8 @@ public class VatAbstractService {
@Autowired
public DataSourceMapper dataSourceMapper;
@Autowired
public DataSourceDetailMapper dataSourceDetailMapper;
@Autowired
public TemplateGroupMapper templateGroupMapper;
@Autowired
public DistributedIDService distributedIDService;
......@@ -59,5 +64,11 @@ public class VatAbstractService {
public BalanceStdManualMapper balanceStdManualMapper;
@Autowired
public BalanceMapper balanceMapper;
@Autowired
public VatEnterpriseAccountDao vatEnterpriseAccountDao;
@Autowired
public ProjectDao projectDao;
@Autowired
public PeriodFormulaBlockMapper periodFormulaBlockMapper;
}
package pwc.taxtech.atms.vat.service.impl.report.functions;
import org.apache.commons.lang3.StringUtils;
import com.alibaba.fastjson.JSON;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.constant.enums.KeyValueConfigResultType;
import pwc.taxtech.atms.dto.vatdto.BSPLFormulaDataSourceDto;
import pwc.taxtech.atms.dto.vatdto.FormulaDataSourceDto;
import pwc.taxtech.atms.entitiy.Project;
import pwc.taxtech.atms.entitiy.ProjectExample;
import pwc.taxtech.atms.vat.entity.BalanceStdManual;
import pwc.taxtech.atms.vat.entity.VatEnterpriseAccount;
import pwc.taxtech.atms.vat.entity.VatStandardAccount;
import pwc.taxtech.atms.vat.entity.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/// <summary>
//**
/// 名称:发生净值
/// 功能:计算指定科目发生额(根据科目自带方向而定)
/// 备注:科目在贷方 则用贷方发生额-借方发生额
......@@ -30,16 +32,18 @@ import java.util.List;
/// <param name="year">会计年份——“0”为当前年份,其他年份则为具体年份;</param>
/// <param name="period">会计期间——“0”为当前月份,1-12为自然月;"99"当年累计</param>
/// <param name="keyParam">摘要(未实现)</param>
public class FSJZ extends FunctionBase implements FreeRefFunction {
private FormulaContext formulaContext;
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
public FSJZ(FormulaContext formulaContext) {
this.formulaContext = formulaContext;
super(formulaContext);
}
@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
Date creatime = new Date();
int accountType, year, period;
String accountCode, keyParam;
......@@ -53,6 +57,9 @@ public class FSJZ extends FunctionBase implements FreeRefFunction {
period = this.getIntParam(args[3], ec);
keyParam = this.getStringParam(args[4], ec);
String formulaExpression = "FSJZ("+accountType+",\""+accountCode+"\","+year+","+period+",\""+keyParam+"\")";
logger.debug(formulaExpression);
if (year == 0) {
year = formulaContext.getYear();
}
......@@ -62,6 +69,7 @@ public class FSJZ extends FunctionBase implements FreeRefFunction {
year = year + yearOffset[0];
if (accountType == 0) {
//标准账套
VatStandardAccount vatStandardAccount = formulaContext.getFormulaAgent().vatStandardAccountMapper.selectOneByAccountCode(accountCode);
if (vatStandardAccount == null) {
return null;
......@@ -69,15 +77,7 @@ public class FSJZ extends FunctionBase implements FreeRefFunction {
BalanceStdManual balanceStdManual = null;
if (year != formulaContext.getYear()) {
ProjectExample example = new ProjectExample();
example.createCriteria().andOrganizationIDEqualTo(formulaContext.getOrganizationID()).andYearEqualTo(year);
Project project = formulaContext.getFormulaAgent().projectMapper.selectByExample(example).get(0);
String dbName = StringUtils.EMPTY;
if (project == null) {
return null;
} else {
dbName = project.getDbName();
}
String dbName = formulaContext.getFormulaAgent().projectDao.getDbNameWithYearAndOrgID(formulaContext.getOrganizationID(), year);
if (period == 99) {
balanceStdManual = formulaContext.getFormulaAgent().balanceStdManualMapper.selectOneWithAccountCodeAndDBName(accountCode, dbName, 12);
......@@ -95,13 +95,17 @@ public class FSJZ extends FunctionBase implements FreeRefFunction {
BigDecimal val = new BigDecimal(0);
List<FormulaDataSourceDto> formulaDataSourceDtoList = new ArrayList<>();
if (balanceStdManual != null) {
List<VatEnterpriseAccount> vatEnterpriseAccountList = formulaContext.getFormulaAgent()
.vatEnterpriseAccountMapper
.getListWithAccountCode(accountCode);
if (period == 99) {
val = new BigDecimal(((balanceStdManual.getYearDebitNet() != null ? balanceStdManual.getYearDebitNet() : 0).doubleValue()
- (balanceStdManual.getYearCreditNet() != null ? balanceStdManual.getYearCreditNet() : 0).doubleValue())
* vatStandardAccount.getDirection());
List<VatEnterpriseAccount> vatEnterpriseAccountList = formulaContext.getFormulaAgent().vatEnterpriseAccountMapper.getListWithAccountCode(accountCode);
for(VatEnterpriseAccount vatEnterpriseAccount:vatEnterpriseAccountList){
BigDecimal amount = formulaContext.getFormulaAgent().balanceMapper.getSumOfBalance(vatEnterpriseAccount.getAcctCode(),vatStandardAccount.getDirection());
for (VatEnterpriseAccount vatEnterpriseAccount : vatEnterpriseAccountList) {
BigDecimal amount = formulaContext.getFormulaAgent()
.balanceMapper
.getSumOfBalance(vatEnterpriseAccount.getAcctCode(), vatStandardAccount.getDirection(), period);
BSPLFormulaDataSourceDto bsplFormulaDataSourceDto = new BSPLFormulaDataSourceDto();
bsplFormulaDataSourceDto.setAccountCode(vatEnterpriseAccount.getAcctCode());
bsplFormulaDataSourceDto.setAccountName(vatEnterpriseAccount.getName());
......@@ -110,14 +114,175 @@ public class FSJZ extends FunctionBase implements FreeRefFunction {
formulaDataSourceDtoList.add(bsplFormulaDataSourceDto);
}
} else {
val = new BigDecimal(((balanceStdManual.getDebitNet() != null ? balanceStdManual.getDebitNet() : 0).doubleValue()
- (balanceStdManual.getCreditNet() != null ? balanceStdManual.getCreditNet() : 0).doubleValue())
* vatStandardAccount.getDirection());
for (VatEnterpriseAccount vatEnterpriseAccount : vatEnterpriseAccountList) {
BigDecimal amount = formulaContext.getFormulaAgent()
.balanceMapper
.getFirstOfBalance(vatEnterpriseAccount.getAcctCode(), vatStandardAccount.getDirection(), period);
BSPLFormulaDataSourceDto bsplFormulaDataSourceDto = new BSPLFormulaDataSourceDto();
bsplFormulaDataSourceDto.setAccountCode(vatEnterpriseAccount.getAcctCode());
bsplFormulaDataSourceDto.setAccountName(vatEnterpriseAccount.getName());
bsplFormulaDataSourceDto.setName("TrialBalanceDataSource");
bsplFormulaDataSourceDto.setAmount(amount);
formulaDataSourceDtoList.add(bsplFormulaDataSourceDto);
}
val = FormulaHelper.roundValue(val, KeyValueConfigResultType.Accounting, null, formulaContext) != null
? FormulaHelper.roundValue(val, KeyValueConfigResultType.Accounting, null, formulaContext) : new BigDecimal(0);
}
}
//todo: sava data
//save datasource
DataSource dataSource = new DataSource();
Long dataSourceID = formulaContext.getFormulaAgent().distributedIDService.nextId();
dataSource.setId(dataSourceID);
dataSource.setType(1);
dataSource.setName("ReportDataSource");
dataSource.setAmount(val);
dataSource.setDescription("");
dataSource.setCreateBy("Admin");
dataSource.setUpdateBy("Admin");
dataSource.setCreateTime(creatime);
dataSource.setUpdateTime(creatime);
dataSource.setRowIndex(ec.getRowIndex());
dataSource.setColumnIndex(ec.getColumnIndex());
dataSource.setRowName("");
dataSource.setColumnName("");
formulaContext.getFormulaAgent().dataSourceMapper.insertSelective(dataSource);
for (FormulaDataSourceDto aFormulaDataSourceDtoList : formulaDataSourceDtoList) {
BSPLFormulaDataSourceDto bsplFormulaDataSourceDto = ((BSPLFormulaDataSourceDto) aFormulaDataSourceDtoList);
DataSourceDetail dataSourceDetail = new DataSourceDetail();
dataSourceDetail.setId(formulaContext.getFormulaAgent().distributedIDService.nextId());
dataSourceDetail.setDataSourceId(dataSourceID);
dataSourceDetail.setDataSourceType(FormulaDataSourceDetailType.BSPLFormulaDataSourceDto.getCode());
dataSourceDetail.setItemValue(JSON.toJSONString(bsplFormulaDataSourceDto));
formulaContext.getFormulaAgent().dataSourceDetailMapper.insertSelective(dataSourceDetail);
}
//save formulablock
Long cellTemplateID = FormulaHelper
.getCellTemplateIDWithTemplateCodeAndColumnIndexAndRowIndex(ec.getWorkbook().getSheetName(ec.getSheetIndex()),ec.getColumnIndex(),ec.getRowIndex(),period,formulaContext);
PeriodFormulaBlock periodFormulaBlock = new PeriodFormulaBlock();
periodFormulaBlock.setId(formulaContext.getFormulaAgent().distributedIDService.nextId());
periodFormulaBlock.setPeriod(period);
periodFormulaBlock.setReportId(0L);
periodFormulaBlock.setCellTemplateId(cellTemplateID);
periodFormulaBlock.setFormulaExpression(formulaExpression);
periodFormulaBlock.setData(val.toString());
periodFormulaBlock.setDataSourceId(dataSourceID);
periodFormulaBlock.setCreateBy("Admin");
periodFormulaBlock.setCreateTime(creatime);
periodFormulaBlock.setUpdateBy("Admin");
periodFormulaBlock.setUpdateTime(creatime);
formulaContext.getFormulaAgent().periodFormulaBlockMapper.insertSelective(periodFormulaBlock);
return new NumberEval(val.doubleValue());
} else {
//企业账套
List<VatEnterpriseAccount> vatEnterpriseAccountList = formulaContext.getFormulaAgent()
.vatEnterpriseAccountDao
.getListByAccountCode(accountCode);
if (vatEnterpriseAccountList == null) {
return null;
}
Balance balance = null;
String dbName = formulaContext.getFormulaAgent().projectDao.getDbNameWithYearAndOrgID(formulaContext.getOrganizationID(), year);
if (period == 99) {
balance = formulaContext.getFormulaAgent().balanceMapper.getFirstWithDbNameAndAccountCodeAndPeriod(dbName, accountCode, 12);
} else {
balance = formulaContext.getFormulaAgent().balanceMapper.getFirstWithDbNameAndAccountCodeAndPeriod(dbName, accountCode, period);
}
BigDecimal val = new BigDecimal(0);
List<FormulaDataSourceDto> dsList = new ArrayList<>();
if (balance != null) {
if (period == 99) {
val = new BigDecimal(((balance.getYearDebitNet() != null ? balance.getYearDebitNet() : 0).doubleValue()
- (balance.getYearCreditNet() != null ? balance.getYearCreditNet() : 0).doubleValue())
* vatEnterpriseAccountList.get(0).getDirection());
BigDecimal amount = formulaContext.getFormulaAgent()
.balanceMapper
.getSumOfBalance(accountCode, vatEnterpriseAccountList.get(0).getDirection(), period);
BSPLFormulaDataSourceDto bsplFormulaDataSourceDto = new BSPLFormulaDataSourceDto();
bsplFormulaDataSourceDto.setAccountCode(vatEnterpriseAccountList.get(0).getAcctCode());
bsplFormulaDataSourceDto.setAccountName(vatEnterpriseAccountList.get(0).getName());
bsplFormulaDataSourceDto.setName("TrialBalanceDataSource");
bsplFormulaDataSourceDto.setAmount(amount);
dsList.add(bsplFormulaDataSourceDto);
} else {
val = new BigDecimal(((balance.getDebitNet() != null ? balance.getDebitNet() : 0).doubleValue()
- (balance.getCreditNet() != null ? balance.getCreditNet() : 0).doubleValue())
* vatEnterpriseAccountList.get(0).getDirection());
BigDecimal amount = formulaContext.getFormulaAgent()
.balanceMapper
.getFirstOfBalance(accountCode, vatEnterpriseAccountList.get(0).getDirection(), period);
BSPLFormulaDataSourceDto bsplFormulaDataSourceDto = new BSPLFormulaDataSourceDto();
bsplFormulaDataSourceDto.setAccountCode(vatEnterpriseAccountList.get(0).getAcctCode());
bsplFormulaDataSourceDto.setAccountName(vatEnterpriseAccountList.get(0).getName());
bsplFormulaDataSourceDto.setName("TrialBalanceDataSource");
bsplFormulaDataSourceDto.setAmount(amount);
dsList.add(bsplFormulaDataSourceDto);
}
val = FormulaHelper.roundValue(val, KeyValueConfigResultType.Accounting, null, formulaContext) != null
? FormulaHelper.roundValue(val, KeyValueConfigResultType.Accounting, null, formulaContext)
: new BigDecimal(0);
}
//todo: sava data
//save datasource
DataSource dataSource = new DataSource();
Long dataSourceID = formulaContext.getFormulaAgent().distributedIDService.nextId();
dataSource.setId(dataSourceID);
dataSource.setType(1);
dataSource.setName("ReportDataSource");
dataSource.setAmount(val);
dataSource.setDescription("");
dataSource.setCreateBy("Admin");
dataSource.setUpdateBy("Admin");
dataSource.setCreateTime(creatime);
dataSource.setUpdateTime(creatime);
dataSource.setRowIndex(ec.getRowIndex());
dataSource.setColumnIndex(ec.getColumnIndex());
dataSource.setRowName("");
dataSource.setColumnName("");
formulaContext.getFormulaAgent().dataSourceMapper.insertSelective(dataSource);
for (FormulaDataSourceDto aFormulaDataSourceDtoList : dsList) {
BSPLFormulaDataSourceDto bsplFormulaDataSourceDto = ((BSPLFormulaDataSourceDto) aFormulaDataSourceDtoList);
DataSourceDetail dataSourceDetail = new DataSourceDetail();
dataSourceDetail.setId(formulaContext.getFormulaAgent().distributedIDService.nextId());
dataSourceDetail.setDataSourceId(dataSourceID);
dataSourceDetail.setDataSourceType(FormulaDataSourceDetailType.BSPLFormulaDataSourceDto.getCode());
dataSourceDetail.setItemValue(JSON.toJSONString(bsplFormulaDataSourceDto));
formulaContext.getFormulaAgent().dataSourceDetailMapper.insertSelective(dataSourceDetail);
}
//save formulablock
Long cellTemplateID = FormulaHelper
.getCellTemplateIDWithTemplateCodeAndColumnIndexAndRowIndex(ec.getWorkbook().getSheetName(ec.getSheetIndex()),ec.getColumnIndex(),ec.getRowIndex(),period,formulaContext);
PeriodFormulaBlock periodFormulaBlock = new PeriodFormulaBlock();
periodFormulaBlock.setId(formulaContext.getFormulaAgent().distributedIDService.nextId());
periodFormulaBlock.setPeriod(period);
periodFormulaBlock.setReportId(0L);
periodFormulaBlock.setCellTemplateId(cellTemplateID);
periodFormulaBlock.setFormulaExpression(formulaExpression);
periodFormulaBlock.setData(val.toString());
periodFormulaBlock.setDataSourceId(dataSourceID);
periodFormulaBlock.setCreateBy("Admin");
periodFormulaBlock.setCreateTime(creatime);
periodFormulaBlock.setUpdateBy("Admin");
periodFormulaBlock.setUpdateTime(creatime);
formulaContext.getFormulaAgent().periodFormulaBlockMapper.insertSelective(periodFormulaBlock);
return new NumberEval(val.doubleValue());
}
return null;
}
}
......@@ -7,8 +7,8 @@ import lombok.Setter;
@Getter
public class FormulaContext {
private String projectID;
private String reportTemplateGroupID;
private String reportID;
private Long reportTemplateGroupID;
private Long reportID;
private String organizationID;
private Integer period;
private Integer year;
......@@ -22,16 +22,19 @@ public class FormulaContext {
private Boolean isIndexAnalysis;
private Boolean cacheHasIndexCode;
// <summary>
// 如果BB公式在cache中取上期失败,是否去上期取
// </summary>
/**
* 如果BB公式在cache中取上期失败,是否去上期取
*/
private Boolean ifCalcStackValue;
// <summary>
// 如果为99,则实时计算;如果为-1,则不用于判断是否实时计算;其他情况会在对应时机计算并保存
// </summary>
/**
* 如果为99,则实时计算;如果为-1,则不用于判断是否实时计算;其他情况会在对应时机计算并保存
*/
private Integer calculateStatus;
// private Map<String, FormulaResult> replaceSpecialCellFormulaDic;
private FormulaAgent formulaAgent;
//private Map<String, FormulaResult> replaceSpecialCellFormulaDic;
}
package pwc.taxtech.atms.vat.service.impl.report.functions;
import pwc.taxtech.atms.constant.enums.KeyValueConfigResultType;
import pwc.taxtech.atms.vat.entity.PeriodTemplate;
import pwc.taxtech.atms.vat.entity.PeriodTemplateExample;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class FormulaHelper {
/**
......@@ -72,4 +81,47 @@ public class FormulaHelper {
return parameterYear;
}
}
/**
* 获取小数点后后几位小数
*
* @param val 目标数据
* @param resultType 键值对结果类型
* @param ifRound 是否精确小数
* @param formulaContext 公式计算上下文
* @return
*/
public static BigDecimal roundValue(BigDecimal val, KeyValueConfigResultType resultType, Boolean ifRound, FormulaContext formulaContext) {
BigDecimal rtn = null;
if (ifRound == null) {
ifRound = formulaContext.getIfRound();
}
if (val != null) {
if (ifRound) {
if (resultType.equals(KeyValueConfigResultType.Percentage)) {
rtn = val.setScale(4, BigDecimal.ROUND_UP);
} else if (resultType.equals(KeyValueConfigResultType.Accounting)) {
rtn = val.setScale(2, BigDecimal.ROUND_UP);
} else if (resultType.equals(KeyValueConfigResultType.Integer)) {
rtn = val.setScale(0);
} else {
rtn = val.setScale(2, BigDecimal.ROUND_UP);
}
} else {
rtn = val;
}
}
return rtn;
}
public static Long getCellTemplateIDWithTemplateCodeAndColumnIndexAndRowIndex(String templateCode, int columnIndex, int rowIndex,int period, FormulaContext formulaContext) {
Map<String,Object> map = new HashMap<>();
map.put("code",templateCode);
map.put("templateGroupID",formulaContext.getReportTemplateGroupID());
map.put("period",period);
map.put("columnIndex",columnIndex);
map.put("rowIndex",rowIndex);
return formulaContext.getFormulaAgent().periodCellTemplateMapper.getCellTemplateIDWithMap(map);
}
}
......@@ -6,6 +6,12 @@ import org.apache.poi.ss.formula.eval.OperandResolver;
import org.apache.poi.ss.formula.eval.ValueEval;
public class FunctionBase {
protected FormulaContext formulaContext;
public FunctionBase(FormulaContext formulaContext){
this.formulaContext = formulaContext;
}
public String getStringParam(ValueEval valueEval, OperationEvaluationContext ec) {
try {
ValueEval v1 = OperandResolver.getSingleValue(valueEval,
......
......@@ -669,5 +669,19 @@
<select id="getSumOfBalance" resultType="java.math.BigDecimal">
SELECT IFNULL(SUM((IFNULL(a.DebitNet,0)-IFNULL(a.CreditNet,0))*#{direction,,jdbcType=INTEGER}),0) FROM Balance a WHERE a.AcctCode=#{acctCode,jdbcType=VARCHAR}
<if test="period!=99">
AND PeriodId=#{period,jdbcType=INTEGER}
</if>
</select>
<select id="getFirstOfBalance" resultType="java.math.BigDecimal">
SELECT IFNULL(((IFNULL(a.DebitNet,0)-IFNULL(a.CreditNet,0))*#{direction,,jdbcType=INTEGER}),0) FROM Balance a WHERE a.AcctCode=#{acctCode,jdbcType=VARCHAR} LIMIT 1
<if test="period!=99">
AND PeriodId=#{period,jdbcType=INTEGER}
</if>
</select>
<select id="getFirstWithDbNameAndAccountCodeAndPeriod" resultMap="BaseResultMap">
SELECT * FROM ${dbName}.Balance a WHERE a.AcctCode=${accountCode,jdbcType=VARCHAR} AND a.PeriodId=${period,jdbcType=INTEGER} LIMIT 1
</select>
</mapper>
\ No newline at end of file
......@@ -501,4 +501,16 @@
)
</foreach>
</insert>
<select id="getCellTemplateIDWithMap" parameterType="Map" resultType="java.lang.Long">
SELECT a.cell_template_id
FROM period_cell_template a
JOIN period_template b
ON a.report_template_id = b.template_id
WHERE b.code = #{code,jdbcType=VARCHAR}
AND b.template_group_id = #{templateGroupID,jdbcType=INTEGER}
AND b.period = #{period,jdbcType=INTEGER}
AND a.column_index = #{columnIndex,jdbcType=INTEGER}
AND a.row_index = #{rowIndex,jdbcType=INTEGER}
AND a.period = #{period,jdbcType=INTEGER}
</select>
</mapper>
\ No newline at end of file
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