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;
}
......@@ -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