Commit cb092a3f authored by frank.xa.zhang's avatar frank.xa.zhang

fixed issues for formula validate

parent c1904df7
......@@ -248,7 +248,8 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp
List<FormulaConfig> dataSourceList = formulaConfigMapper.selectByExample(example);
List<String> nameList = new ArrayList<>();
FormulaHelper formulaHelper = new FormulaHelper();
String tmpFormula = formulaHelper.formatFormula(formula).toUpperCase();
// String tmpFormula = formulaHelper.formatFormula(formula).toUpperCase();
String tmpFormula = formula.toUpperCase();
for (FormulaConfig dataSource : dataSourceList) {
if (tmpFormula.contains(dataSource.getFormulaName().toUpperCase() + "(") && !nameList.contains(dataSource.getDataSourceName())) {
......
......@@ -65,7 +65,9 @@ public final class FormulaHelper {
while (!regexMatchObjectStack.empty()) {
RegexMatchObject obj = regexMatchObjectStack.pop();
formula = formula.substring(0, obj.getIndex()) + obj.getExpression() + formula.substring(obj.getIndex(), obj.getLength());
formula = formula.substring(0, obj.getIndex())
+ obj.getExpression()
+ formula.substring(obj.getIndex(), obj.getIndex() + obj.getLength());
}
return formula.trim();
}
......
package pwc.taxtech.atms.service.impl;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.FormulaParseException;
import org.apache.poi.ss.formula.FormulaParser;
import org.apache.poi.ss.formula.FormulaType;
import org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.service.TemplateFormulaService;
......@@ -22,8 +27,17 @@ public class TemplateFormulaServiceImpl extends AbstractService implements Templ
}
try {
String tidyFormula = formulaHelper.formatFormula(formula);
//String tidyFormula = formulaHelper.formatFormula(formula);
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFEvaluationWorkbook xssfEvaluationWorkbook = XSSFEvaluationWorkbook.create(workbook);
try {
FormulaParser.parse(formula, xssfEvaluationWorkbook, FormulaType.CELL, 0);
result.setResult(true);
return result;
} catch (FormulaParseException e) {
result.setResult(false);
result.setResultMsg(e.getMessage());
}
/*todo: find the replace solution for here to check formual is correct or not
//var sourceCode = m_engine.CreateScriptSourceFromString(tidyFormula, SourceCodeKind.AutoDetect);
//var compileCode = sourceCode.Compile();
......
......@@ -124,7 +124,9 @@ public interface DataSourceMapper extends MyVatMapper {
void clearDataSourceDetailWithPeriod(@Param("period") Integer period);
void clearCellDataWithPeriod(@Param("exceptReportTemplateIDs") String exceptReportTemplateIDs);
void clearCellDataWithPeriod(@Param("exceptReportTemplateIDs") String exceptReportTemplateIDs,@Param("period")Integer period);
void clearReportWithPeriod(Integer period);
List<DataSourceExtendDto> getFormulaDataSource(Long reportID);
}
\ No newline at end of file
......@@ -105,4 +105,6 @@ public interface PeriodFormulaBlockMapper extends MyVatMapper {
* @mbg.generated
*/
int updateByPrimaryKey(PeriodFormulaBlock record);
void updateReportId(@Param("reportId") Long reportId,@Param("cellTemplateConfigIds") List<Long> cellTemplateConfigIds,@Param("period") Integer period);
}
\ No newline at end of file
......@@ -114,7 +114,8 @@ public class ReportServiceImpl extends VatAbstractService implements ReportServi
dataSourceMapper.clearTaxPayerReportWithPeriod(period);
dataSourceMapper.clearDataSourceWithPeriod(period);
dataSourceMapper.clearDataSourceDetailWithPeriod(period);
dataSourceMapper.clearCellDataWithPeriod(strExceptTemplateIDs);
dataSourceMapper.clearCellDataWithPeriod(strExceptTemplateIDs,period);
dataSourceMapper.clearReportWithPeriod(period);
// 根据templategroupid 把 template 插入到 periodTemplate
TemplateExample example = new TemplateExample();
......
......@@ -267,7 +267,7 @@ public class FSJZ extends FunctionBase implements FreeRefFunction {
PeriodFormulaBlock periodFormulaBlock = new PeriodFormulaBlock();
periodFormulaBlock.setId(SpringContextUtil.distributedIDService.nextId());
periodFormulaBlock.setPeriod(period);
periodFormulaBlock.setReportId(0L);
periodFormulaBlock.setReportId(0L);//todo:update reportID when report data generated
periodFormulaBlock.setCellTemplateId(cellTemplateID);
periodFormulaBlock.setFormulaExpression(formulaExpression);
periodFormulaBlock.setData(val.toString());
......
......@@ -36,6 +36,4 @@ public class FormulaContext {
private FormulaAgent formulaAgent;
//private Map<String, FormulaResult> replaceSpecialCellFormulaDic;
}
......@@ -93,7 +93,7 @@
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
id, `type`, `name`, amount, description, key_value_data_id, create_by, create_time,
id, `type`, `name`, amount, description, key_value_data_id, create_by, create_time,
update_by, update_time, row_name, `column_name`, row_index, remap_batch_id, column_index
</sql>
<select id="selectByExample" parameterType="pwc.taxtech.atms.vat.entity.DataSourceExample" resultMap="BaseResultMap">
......@@ -119,7 +119,7 @@
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
select
<include refid="Base_Column_List" />
from data_source
where id = #{id,jdbcType=BIGINT}
......@@ -147,16 +147,16 @@
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
insert into data_source (id, `type`, `name`,
amount, description, key_value_data_id,
create_by, create_time, update_by,
update_time, row_name, `column_name`,
insert into data_source (id, `type`, `name`,
amount, description, key_value_data_id,
create_by, create_time, update_by,
update_time, row_name, `column_name`,
row_index, remap_batch_id, column_index
)
values (#{id,jdbcType=BIGINT}, #{type,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},
#{amount,jdbcType=DECIMAL}, #{description,jdbcType=VARCHAR}, #{keyValueDataId,jdbcType=VARCHAR},
#{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR},
#{updateTime,jdbcType=TIMESTAMP}, #{rowName,jdbcType=VARCHAR}, #{columnName,jdbcType=VARCHAR},
values (#{id,jdbcType=BIGINT}, #{type,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},
#{amount,jdbcType=DECIMAL}, #{description,jdbcType=VARCHAR}, #{keyValueDataId,jdbcType=VARCHAR},
#{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR},
#{updateTime,jdbcType=TIMESTAMP}, #{rowName,jdbcType=VARCHAR}, #{columnName,jdbcType=VARCHAR},
#{rowIndex,jdbcType=INTEGER}, #{remapBatchId,jdbcType=VARCHAR}, #{columnIndex,jdbcType=INTEGER}
)
</insert>
......@@ -454,35 +454,38 @@
<delete id="clearCellTemplateWithPeriod">
DELETE FROM period_cell_template WHERE period=#{period,jdbcType=INTEGER}
<if test="exceptReportTemplateIDs!=null and exceptReportTemplateIDs!=''">
and id not in (${exceptReportTemplateIDs});
and report_template_id not in (${exceptReportTemplateIDs});
</if>
</delete>
<delete id="clearCellTemplateConfigWithPeriod">
DELETE FROM period_cell_template_config WHERE period=#{period,jdbcType=INTEGER}
<if test="exceptReportTemplateIDs!=null and exceptReportTemplateIDs!=''">
and id not in (${exceptReportTemplateIDs});
and report_template_id not in (${exceptReportTemplateIDs});
</if>
</delete>
<delete id="clearTemplateWithPeriod">
DELETE FROM period_template WHERE period=#{period,jdbcType=INTEGER}
<if test="exceptReportTemplateIDs!=null and exceptReportTemplateIDs!=''">
and id not in (${exceptReportTemplateIDs});
and template_id not in (${exceptReportTemplateIDs});
</if>
</delete>
<delete id="clearTaxPayerReportWithPeriod">
DELETE FROM period_tax_payer_report_rule WHERE period=#{period,jdbcType=INTEGER};
</delete>
<delete id="clearDataSourceWithPeriod">
DELETE d FROM data_source d JOIN period_formula_block f ON d.id = f.data_source_id WHERE f.Period = #{period,jdbcType=INTEGER};
DELETE d FROM data_source d JOIN period_formula_block f ON d.id = f.data_source_id WHERE f.period = #{period,jdbcType=INTEGER};
</delete>
<delete id="clearDataSourceDetailWithPeriod">
DELETE d FROM data_source_detail d JOIN period_formula_block f ON d.data_source_id = f.data_source_id WHERE f.Period = #{period,jdbcType=INTEGER};
DELETE d FROM data_source_detail d JOIN period_formula_block f ON d.data_source_id = f.data_source_id WHERE f.period = #{period,jdbcType=INTEGER};
</delete>
<delete id="clearCellDataWithPeriod">
DELETE FROM cell_data
<if test="exceptReportTemplateIDs!=null and exceptReportTemplateIDs!=''">
WHERE report_id not in (${exceptReportTemplateIDs});
</if>
DELETE c FROM cell_data c join report r on c.report_id=r.id where r.period = #{period,jdbcType=INTEGER};
<!--<if test="exceptReportTemplateIDs!=null and exceptReportTemplateIDs!=''">-->
<!--WHERE report_id not in (${exceptReportTemplateIDs});-->
<!--</if>-->
</delete>
<delete id="clearReportWithPeriod">
DELETE FROM report WHERE period=#{period,jdbcType=INTEGER};
</delete>
<resultMap id="DataSourceExtendDtoMap" type="pwc.taxtech.atms.dto.vatdto.DataSourceExtendDto">
<id column="id" jdbcType="BIGINT" property="id" />
......@@ -504,7 +507,6 @@
<result column="cell_template_id" jdbcType="BIGINT" property="cellTemplateID" />
<result column="cell_data_id" jdbcType="BIGINT" property="cellDataID" />
</resultMap>
<select id="getFormulaDataSource" parameterType="java.lang.Long" resultMap="DataSourceExtendDtoMap">
SELECT
ds.*,
......
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