Commit 6827f086 authored by frank.xa.zhang's avatar frank.xa.zhang

Merge branch 'dev' into dev_frank

# Conflicts:
#	atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/report/functions/FormulaContext.java
parents f8ee5152 788e071a
......@@ -316,8 +316,11 @@
<artifactId>guava</artifactId>
<version>24.0-jre</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty.aggregate/jetty-all -->
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty.aggregate/jetty-all -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.eclipse.jetty.aggregate</groupId>-->
<!--<artifactId>jetty-all</artifactId>-->
......
package pwc.taxtech.atms.dao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import pwc.taxtech.atms.MyMapper;
import pwc.taxtech.atms.dto.GroupId;
import pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto;
import java.util.List;
@Mapper
public interface FormulaAdminMapper extends MyMapper {
@Select("SELECT " +
" cell_template.ID AS cellTemplateID, " +
" template.ID AS reportTemplateID, " +
" template.template_group_id AS reportTemplateGroupID, " +
" cell_template_config.formula AS formula, " +
" cell_template.row_index AS rowIndex, " +
" cell_template.column_index AS columnIndex, " +
" template.Code AS reportCode, " +
" cell_template.column_name AS columnName, " +
" cell_template.row_name AS rowName, " +
" cell_template.data_type AS resultType " +
"FROM " +
" template " +
" JOIN " +
" cell_template ON template.id = cell_template.report_template_id " +
" JOIN " +
" cell_template_config ON cell_template.id = cell_template_config.cell_template_id " +
"WHERE " +
" cell_template_config.data_source_type = 1 " +
" AND template.template_group_id = #{groupId}")
List<CellTemplatePerGroupDto> getCellTemplatePerGroupDto(@Param("groupId") String groupId);
@Select("SELECT " +
" rule.template_group_id as groupId, rule.is_default as isDefault " +
"FROM " +
" Project p, " +
" tax_payer_report_rule rule " +
"WHERE " +
" (p.OrganizationID = rule.organization_id " +
" OR rule.is_default = 1) " +
" AND p.ID = #{projectId}")
List<GroupId> getTemplateGroupId(@Param("projectId") String projectId);
}
package pwc.taxtech.atms.dto;
public class GroupId {
public String groupId;
public Integer isDefault;
}
package pwc.taxtech.atms.utils;
import java.util.Map;
public class FormulaContext {
private String projectID;
private String reportTemplateGroupID;
private String reportID;
private String organizationID;
private Integer period;
private Integer year;
private Boolean isYear;
private String indexResultId;
private Integer yearBeginPeriod;
private Integer yearEndPeriod;
private Boolean ifRound;
private Boolean isValidation;
private Boolean isDetailed;
private Boolean isIndexAnalysis;
private Boolean cacheHasIndexCode;
// <summary>
// 如果BB公式在cache中取上期失败,是否去上期取
// </summary>
private Boolean ifCalcStackValue;
// <summary>
// 如果为99,则实时计算;如果为-1,则不用于判断是否实时计算;其他情况会在对应时机计算并保存
// </summary>
private Integer calculateStatus;
private Map<String, FormulaResult> replaceSpecialCellFormulaDic;
public String getProjectID() {
return projectID;
}
public void setProjectID(String projectID) {
this.projectID = projectID;
}
public String getReportTemplateGroupID() {
return reportTemplateGroupID;
}
public void setReportTemplateGroupID(String reportTemplateGroupID) {
this.reportTemplateGroupID = reportTemplateGroupID;
}
public String getReportID() {
return reportID;
}
public void setReportID(String reportID) {
this.reportID = reportID;
}
public String getOrganizationID() {
return organizationID;
}
public void setOrganizationID(String organizationID) {
this.organizationID = organizationID;
}
public Integer getPeriod() {
return period;
}
public void setPeriod(Integer period) {
this.period = period;
}
public Integer getYear() {
return year;
}
public void setYear(Boolean year) {
isYear = year;
}
public String getIndexResultId() {
return indexResultId;
}
public void setIndexResultId(String indexResultId) {
this.indexResultId = indexResultId;
}
public Integer getYearBeginPeriod() {
return yearBeginPeriod;
}
public void setYearBeginPeriod(Integer yearBeginPeriod) {
this.yearBeginPeriod = yearBeginPeriod;
}
public Integer getYearEndPeriod() {
return yearEndPeriod;
}
public void setYearEndPeriod(Integer yearEndPeriod) {
this.yearEndPeriod = yearEndPeriod;
}
public Boolean getIfRound() {
return ifRound;
}
public void setIfRound(Boolean ifRound) {
this.ifRound = ifRound;
}
public Boolean getValidation() {
return isValidation;
}
public void setValidation(Boolean validation) {
isValidation = validation;
}
public Boolean getDetailed() {
return isDetailed;
}
public void setDetailed(Boolean detailed) {
isDetailed = detailed;
}
public Boolean getIndexAnalysis() {
return isIndexAnalysis;
}
public void setIndexAnalysis(Boolean indexAnalysis) {
isIndexAnalysis = indexAnalysis;
}
public Boolean getCacheHasIndexCode() {
return cacheHasIndexCode;
}
public void setCacheHasIndexCode(Boolean cacheHasIndexCode) {
this.cacheHasIndexCode = cacheHasIndexCode;
}
public Boolean getIfCalcStackValue() {
return ifCalcStackValue;
}
public void setIfCalcStackValue(Boolean ifCalcStackValue) {
this.ifCalcStackValue = ifCalcStackValue;
}
public Integer getCalculateStatus() {
return calculateStatus;
}
public void setCalculateStatus(Integer calculateStatus) {
this.calculateStatus = calculateStatus;
}
public Map<String, FormulaResult> getReplaceSpecialCellFormulaDic() {
return replaceSpecialCellFormulaDic;
}
public void setReplaceSpecialCellFormulaDic(Map<String, FormulaResult> replaceSpecialCellFormulaDic) {
this.replaceSpecialCellFormulaDic = replaceSpecialCellFormulaDic;
}
public void setYear(Integer year) {
this.year = year;
}
}
package pwc.taxtech.atms.utils;
import pwc.taxtech.atms.dto.vatdto.FormulaDataSourceDto;
import java.util.ArrayList;
import java.util.List;
public class FormulaResult {
private static final List<FormulaDataSourceDto> emptyDataSourceList = new ArrayList<>();
private Boolean isNullCalculated ;
// If the calculation is canceled. May be used while report generation
private Boolean isCanceled ;
private Object data ;
private String exp ;
private String description ;
// 是否需要四舍五入
private Boolean ifRound ;
// 1: Number, 2: Percentage, 3: Boolean, 4: String, 5: Integer
// If null, means we do not know the type exactly.
// public KeyValueConfigResultType? ResultType ;
// private EnumOperationType operationType ;
private Boolean isValidation ;
private List<FormulaDataSourceDto> dataSourceList ;
public FormulaResult(Object data)
{
this.data = data;
}
}
package pwc.taxtech.atms.vat.dao;
import org.apache.ibatis.annotations.Mapper;
import pwc.taxtech.atms.MyVatMapper;
@Mapper
public interface FormulaProjectMapper extends MyVatMapper {
}
package pwc.taxtech.atms.service.impl;
package pwc.taxtech.atms.vat.service.impl;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.EvaluationException;
......@@ -7,16 +7,27 @@ 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.utils.FormulaContext;
import pwc.taxtech.atms.constant.enums.EnumServiceType;
import pwc.taxtech.atms.dto.GroupId;
import pwc.taxtech.atms.dto.vatdto.CellTemplatePerGroupDto;
import pwc.taxtech.atms.entitiy.ProjectServiceType;
import pwc.taxtech.atms.entitiy.ProjectServiceTypeExample;
import pwc.taxtech.atms.vat.service.impl.report.functions.FormulaAgent;
import pwc.taxtech.atms.vat.service.impl.report.functions.FormulaContext;
import java.util.Comparator;
import java.util.List;
public class ReportFormulaFactory {
static final Logger LOGGER = LoggerFactory.getLogger(ReportFormulaFactory.class);
public static abstract class ReportBaseFormula implements FreeRefFunction {
final FormulaContext context;
final FormulaAgent agent;
protected ReportBaseFormula(FormulaContext context) {
this.context = context;
this.agent = context.getFormulaAgent();
}
static String resolverString(ValueEval[] args, OperationEvaluationContext ec, int index)
......@@ -31,24 +42,114 @@ public class ReportFormulaFactory {
ec.getColumnIndex()));
}
static Boolean resolverBoolean(ValueEval[] args, OperationEvaluationContext ec, int index)
throws EvaluationException {
return OperandResolver.coerceValueToBoolean(OperandResolver.getSingleValue(args[index], ec.getRowIndex(),
ec.getColumnIndex()), false);
}
static Double resolverDouble(ValueEval[] args, OperationEvaluationContext ec, int index)
throws EvaluationException {
return OperandResolver.coerceValueToDouble(OperandResolver.getSingleValue(args[index], ec.getRowIndex(),
ec.getColumnIndex()));
}
static class Period {
int yearOffset = 0;
int period;
public Period(int period) {
this.period = period;
}
public Period set(int yearOffset) {
this.yearOffset = yearOffset;
return this;
}
}
Period getPeriod(int parameterPeriod) {
int yearOffset = 0;
if (parameterPeriod == -99) {
return new Period(parameterPeriod);
} else if (parameterPeriod <= -1) {
Integer period = parameterPeriod + context.getPeriod();
while (period <= 0) {
yearOffset--;
period += 12;
//throw new NotImplementedException();
}
return new Period(period).set(yearOffset);
} else if (parameterPeriod == 0) {
return new Period(context.getPeriod());
} else {
return new Period(parameterPeriod);
}
}
public int getYear(int parameterYear) {
if (parameterYear <= -1) {
return parameterYear + context.getYear();
} else if (parameterYear == 0) {
return context.getYear();
} else {
return parameterYear;
}
}
}
public static class BB extends ReportBaseFormula {
String reportCode;
Integer columnIndex;
Integer rowIndex;
Integer period;
Integer year;
protected BB(FormulaContext context) {
super(context);
}
void resolverArgs(ValueEval[] args, OperationEvaluationContext ec) throws EvaluationException {
reportCode = resolverString(args, ec, 0);
columnIndex = resolverInteger(args, ec, 1);
rowIndex = resolverInteger(args, ec, 3);
period = resolverInteger(args, ec, 4);
year = resolverInteger(args, ec, 5);
}
@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
try {
String v1 = OperandResolver.coerceValueToString(OperandResolver.getSingleValue(args[0], ec.getRowIndex(), ec.getColumnIndex()));
resolverArgs(args, ec);
Period curPeriod = getPeriod(period.intValue());
curPeriod.set(curPeriod.yearOffset + getYear(year));
ProjectServiceTypeExample pst = new ProjectServiceTypeExample();
pst.createCriteria().andTemplateGroupIDEqualTo(Long.valueOf(context.getReportTemplateGroupID()))
.andServiceTypeIDEqualTo(EnumServiceType.VAT.getCode() + "");
List<ProjectServiceType> pstReult = agent.projectServiceTypeMapper.selectByExample(pst);
List<CellTemplatePerGroupDto> cellTemplates = agent.adminMp.getCellTemplatePerGroupDto(context.getReportTemplateGroupID());
if (pstReult == null || pstReult.isEmpty()) {
List<GroupId> groupIds = agent.adminMp.getTemplateGroupId(context.getProjectID());
GroupId groupId;
if (groupIds.size() > 0) {
groupId = groupIds.stream().filter(m -> m.isDefault != 1).findFirst().get();
if (groupId == null) groupId = groupIds.get(0);
cellTemplates.addAll(agent.adminMp.getCellTemplatePerGroupDto(groupId.groupId));
}
}
} catch (EvaluationException e) {
LOGGER.warn("resole args some exception", e);
e.printStackTrace();
}
......
package pwc.taxtech.atms.vat.service.impl.report.functions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.dao.FormulaAdminMapper;
import pwc.taxtech.atms.vat.dao.FormulaProjectMapper;
import pwc.taxtech.atms.vat.service.impl.VatAbstractService;
@Service
public class FormulaAgent extends VatAbstractService {
@Autowired
public FormulaAdminMapper adminMp;
@Autowired
public FormulaProjectMapper projectMp;
}
package pwc.taxtech.atms.vat.service.impl.report.functions;
import pwc.taxtech.atms.utils.FormulaResult;
import pwc.taxtech.atms.vat.dao.PeriodTemplateMapper;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
public class FormulaContext {
private String projectID;
private String reportTemplateGroupID;
......@@ -21,7 +21,7 @@ public class FormulaContext {
private Boolean isDetailed;
private Boolean isIndexAnalysis;
private Boolean cacheHasIndexCode;
private FormulaAgent formulaAgent;
// <summary>
// 如果BB公式在cache中取上期失败,是否去上期取
......@@ -31,161 +31,7 @@ public class FormulaContext {
// 如果为99,则实时计算;如果为-1,则不用于判断是否实时计算;其他情况会在对应时机计算并保存
// </summary>
private Integer calculateStatus;
private Map<String, FormulaResult> replaceSpecialCellFormulaDic;
public String getProjectID() {
return projectID;
}
public void setProjectID(String projectID) {
this.projectID = projectID;
}
public String getReportTemplateGroupID() {
return reportTemplateGroupID;
}
public void setReportTemplateGroupID(String reportTemplateGroupID) {
this.reportTemplateGroupID = reportTemplateGroupID;
}
public String getReportID() {
return reportID;
}
public void setReportID(String reportID) {
this.reportID = reportID;
}
public String getOrganizationID() {
return organizationID;
}
public void setOrganizationID(String organizationID) {
this.organizationID = organizationID;
}
public Integer getPeriod() {
return period;
}
public void setPeriod(Integer period) {
this.period = period;
}
public Integer getYear() {
return year;
}
public void setYear(Boolean year) {
isYear = year;
}
public String getIndexResultId() {
return indexResultId;
}
public void setIndexResultId(String indexResultId) {
this.indexResultId = indexResultId;
}
public Integer getYearBeginPeriod() {
return yearBeginPeriod;
}
public void setYearBeginPeriod(Integer yearBeginPeriod) {
this.yearBeginPeriod = yearBeginPeriod;
}
public Integer getYearEndPeriod() {
return yearEndPeriod;
}
public void setYearEndPeriod(Integer yearEndPeriod) {
this.yearEndPeriod = yearEndPeriod;
}
public Boolean getIfRound() {
return ifRound;
}
public void setIfRound(Boolean ifRound) {
this.ifRound = ifRound;
}
public Boolean getValidation() {
return isValidation;
}
public void setValidation(Boolean validation) {
isValidation = validation;
}
public Boolean getDetailed() {
return isDetailed;
}
public void setDetailed(Boolean detailed) {
isDetailed = detailed;
}
public Boolean getIndexAnalysis() {
return isIndexAnalysis;
}
public void setIndexAnalysis(Boolean indexAnalysis) {
isIndexAnalysis = indexAnalysis;
}
public Boolean getCacheHasIndexCode() {
return cacheHasIndexCode;
}
public void setCacheHasIndexCode(Boolean cacheHasIndexCode) {
this.cacheHasIndexCode = cacheHasIndexCode;
}
public Boolean getIfCalcStackValue() {
return ifCalcStackValue;
}
public void setIfCalcStackValue(Boolean ifCalcStackValue) {
this.ifCalcStackValue = ifCalcStackValue;
}
public Integer getCalculateStatus() {
return calculateStatus;
}
public void setCalculateStatus(Integer calculateStatus) {
this.calculateStatus = calculateStatus;
}
public Map<String, FormulaResult> getReplaceSpecialCellFormulaDic() {
return replaceSpecialCellFormulaDic;
}
public void setReplaceSpecialCellFormulaDic(Map<String, FormulaResult> replaceSpecialCellFormulaDic) {
this.replaceSpecialCellFormulaDic = replaceSpecialCellFormulaDic;
}
public void setYear(Integer year) {
this.year = year;
}
public Boolean getIsYear() {
return isYear;
}
public void setIsYear(Boolean isYear) {
isYear = isYear;
}
public FormulaAgent getFormulaAgent() {
return formulaAgent;
}
// private Map<String, FormulaResult> replaceSpecialCellFormulaDic;
private FormulaAgent formulaAgent;
public void setFormulaAgent(FormulaAgent formulaAgent) {
this.formulaAgent = formulaAgent;
}
}
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