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 ...@@ -248,7 +248,8 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp
List<FormulaConfig> dataSourceList = formulaConfigMapper.selectByExample(example); List<FormulaConfig> dataSourceList = formulaConfigMapper.selectByExample(example);
List<String> nameList = new ArrayList<>(); List<String> nameList = new ArrayList<>();
FormulaHelper formulaHelper = new FormulaHelper(); FormulaHelper formulaHelper = new FormulaHelper();
String tmpFormula = formulaHelper.formatFormula(formula).toUpperCase(); // String tmpFormula = formulaHelper.formatFormula(formula).toUpperCase();
String tmpFormula = formula.toUpperCase();
for (FormulaConfig dataSource : dataSourceList) { for (FormulaConfig dataSource : dataSourceList) {
if (tmpFormula.contains(dataSource.getFormulaName().toUpperCase() + "(") && !nameList.contains(dataSource.getDataSourceName())) { if (tmpFormula.contains(dataSource.getFormulaName().toUpperCase() + "(") && !nameList.contains(dataSource.getDataSourceName())) {
......
...@@ -65,7 +65,9 @@ public final class FormulaHelper { ...@@ -65,7 +65,9 @@ public final class FormulaHelper {
while (!regexMatchObjectStack.empty()) { while (!regexMatchObjectStack.empty()) {
RegexMatchObject obj = regexMatchObjectStack.pop(); 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(); return formula.trim();
} }
......
package pwc.taxtech.atms.service.impl; package pwc.taxtech.atms.service.impl;
import org.apache.commons.lang3.StringUtils; 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 org.springframework.stereotype.Service;
import pwc.taxtech.atms.dto.OperationResultDto; import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.service.TemplateFormulaService; import pwc.taxtech.atms.service.TemplateFormulaService;
...@@ -22,8 +27,17 @@ public class TemplateFormulaServiceImpl extends AbstractService implements Templ ...@@ -22,8 +27,17 @@ public class TemplateFormulaServiceImpl extends AbstractService implements Templ
} }
try { 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 /*todo: find the replace solution for here to check formual is correct or not
//var sourceCode = m_engine.CreateScriptSourceFromString(tidyFormula, SourceCodeKind.AutoDetect); //var sourceCode = m_engine.CreateScriptSourceFromString(tidyFormula, SourceCodeKind.AutoDetect);
//var compileCode = sourceCode.Compile(); //var compileCode = sourceCode.Compile();
......
...@@ -124,7 +124,9 @@ public interface DataSourceMapper extends MyVatMapper { ...@@ -124,7 +124,9 @@ public interface DataSourceMapper extends MyVatMapper {
void clearDataSourceDetailWithPeriod(@Param("period") Integer period); 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); List<DataSourceExtendDto> getFormulaDataSource(Long reportID);
} }
\ No newline at end of file
...@@ -105,4 +105,6 @@ public interface PeriodFormulaBlockMapper extends MyVatMapper { ...@@ -105,4 +105,6 @@ public interface PeriodFormulaBlockMapper extends MyVatMapper {
* @mbg.generated * @mbg.generated
*/ */
int updateByPrimaryKey(PeriodFormulaBlock record); 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 ...@@ -114,7 +114,8 @@ public class ReportServiceImpl extends VatAbstractService implements ReportServi
dataSourceMapper.clearTaxPayerReportWithPeriod(period); dataSourceMapper.clearTaxPayerReportWithPeriod(period);
dataSourceMapper.clearDataSourceWithPeriod(period); dataSourceMapper.clearDataSourceWithPeriod(period);
dataSourceMapper.clearDataSourceDetailWithPeriod(period); dataSourceMapper.clearDataSourceDetailWithPeriod(period);
dataSourceMapper.clearCellDataWithPeriod(strExceptTemplateIDs); dataSourceMapper.clearCellDataWithPeriod(strExceptTemplateIDs,period);
dataSourceMapper.clearReportWithPeriod(period);
// 根据templategroupid 把 template 插入到 periodTemplate // 根据templategroupid 把 template 插入到 periodTemplate
TemplateExample example = new TemplateExample(); TemplateExample example = new TemplateExample();
......
...@@ -267,7 +267,7 @@ public class FSJZ extends FunctionBase implements FreeRefFunction { ...@@ -267,7 +267,7 @@ public class FSJZ extends FunctionBase implements FreeRefFunction {
PeriodFormulaBlock periodFormulaBlock = new PeriodFormulaBlock(); PeriodFormulaBlock periodFormulaBlock = new PeriodFormulaBlock();
periodFormulaBlock.setId(SpringContextUtil.distributedIDService.nextId()); periodFormulaBlock.setId(SpringContextUtil.distributedIDService.nextId());
periodFormulaBlock.setPeriod(period); periodFormulaBlock.setPeriod(period);
periodFormulaBlock.setReportId(0L); periodFormulaBlock.setReportId(0L);//todo:update reportID when report data generated
periodFormulaBlock.setCellTemplateId(cellTemplateID); periodFormulaBlock.setCellTemplateId(cellTemplateID);
periodFormulaBlock.setFormulaExpression(formulaExpression); periodFormulaBlock.setFormulaExpression(formulaExpression);
periodFormulaBlock.setData(val.toString()); periodFormulaBlock.setData(val.toString());
......
...@@ -36,6 +36,4 @@ public class FormulaContext { ...@@ -36,6 +36,4 @@ public class FormulaContext {
private FormulaAgent formulaAgent; private FormulaAgent formulaAgent;
//private Map<String, FormulaResult> replaceSpecialCellFormulaDic; //private Map<String, FormulaResult> replaceSpecialCellFormulaDic;
} }
...@@ -454,35 +454,38 @@ ...@@ -454,35 +454,38 @@
<delete id="clearCellTemplateWithPeriod"> <delete id="clearCellTemplateWithPeriod">
DELETE FROM period_cell_template WHERE period=#{period,jdbcType=INTEGER} DELETE FROM period_cell_template WHERE period=#{period,jdbcType=INTEGER}
<if test="exceptReportTemplateIDs!=null and exceptReportTemplateIDs!=''"> <if test="exceptReportTemplateIDs!=null and exceptReportTemplateIDs!=''">
and id not in (${exceptReportTemplateIDs}); and report_template_id not in (${exceptReportTemplateIDs});
</if> </if>
</delete> </delete>
<delete id="clearCellTemplateConfigWithPeriod"> <delete id="clearCellTemplateConfigWithPeriod">
DELETE FROM period_cell_template_config WHERE period=#{period,jdbcType=INTEGER} DELETE FROM period_cell_template_config WHERE period=#{period,jdbcType=INTEGER}
<if test="exceptReportTemplateIDs!=null and exceptReportTemplateIDs!=''"> <if test="exceptReportTemplateIDs!=null and exceptReportTemplateIDs!=''">
and id not in (${exceptReportTemplateIDs}); and report_template_id not in (${exceptReportTemplateIDs});
</if> </if>
</delete> </delete>
<delete id="clearTemplateWithPeriod"> <delete id="clearTemplateWithPeriod">
DELETE FROM period_template WHERE period=#{period,jdbcType=INTEGER} DELETE FROM period_template WHERE period=#{period,jdbcType=INTEGER}
<if test="exceptReportTemplateIDs!=null and exceptReportTemplateIDs!=''"> <if test="exceptReportTemplateIDs!=null and exceptReportTemplateIDs!=''">
and id not in (${exceptReportTemplateIDs}); and template_id not in (${exceptReportTemplateIDs});
</if> </if>
</delete> </delete>
<delete id="clearTaxPayerReportWithPeriod"> <delete id="clearTaxPayerReportWithPeriod">
DELETE FROM period_tax_payer_report_rule WHERE period=#{period,jdbcType=INTEGER}; DELETE FROM period_tax_payer_report_rule WHERE period=#{period,jdbcType=INTEGER};
</delete> </delete>
<delete id="clearDataSourceWithPeriod"> <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>
<delete id="clearDataSourceDetailWithPeriod"> <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>
<delete id="clearCellDataWithPeriod"> <delete id="clearCellDataWithPeriod">
DELETE FROM cell_data 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!=''"> <!--<if test="exceptReportTemplateIDs!=null and exceptReportTemplateIDs!=''">-->
WHERE report_id not in (${exceptReportTemplateIDs}); <!--WHERE report_id not in (${exceptReportTemplateIDs});-->
</if> <!--</if>-->
</delete>
<delete id="clearReportWithPeriod">
DELETE FROM report WHERE period=#{period,jdbcType=INTEGER};
</delete> </delete>
<resultMap id="DataSourceExtendDtoMap" type="pwc.taxtech.atms.dto.vatdto.DataSourceExtendDto"> <resultMap id="DataSourceExtendDtoMap" type="pwc.taxtech.atms.dto.vatdto.DataSourceExtendDto">
<id column="id" jdbcType="BIGINT" property="id" /> <id column="id" jdbcType="BIGINT" property="id" />
...@@ -504,7 +507,6 @@ ...@@ -504,7 +507,6 @@
<result column="cell_template_id" jdbcType="BIGINT" property="cellTemplateID" /> <result column="cell_template_id" jdbcType="BIGINT" property="cellTemplateID" />
<result column="cell_data_id" jdbcType="BIGINT" property="cellDataID" /> <result column="cell_data_id" jdbcType="BIGINT" property="cellDataID" />
</resultMap> </resultMap>
<select id="getFormulaDataSource" parameterType="java.lang.Long" resultMap="DataSourceExtendDtoMap"> <select id="getFormulaDataSource" parameterType="java.lang.Long" resultMap="DataSourceExtendDtoMap">
SELECT SELECT
ds.*, ds.*,
......
...@@ -6,17 +6,17 @@ ...@@ -6,17 +6,17 @@
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
--> -->
<id column="id" jdbcType="BIGINT" property="id" /> <id column="id" jdbcType="BIGINT" property="id"/>
<result column="period" jdbcType="INTEGER" property="period" /> <result column="period" jdbcType="INTEGER" property="period"/>
<result column="report_id" jdbcType="BIGINT" property="reportId" /> <result column="report_id" jdbcType="BIGINT" property="reportId"/>
<result column="cell_template_id" jdbcType="BIGINT" property="cellTemplateId" /> <result column="cell_template_id" jdbcType="BIGINT" property="cellTemplateId"/>
<result column="formula_expression" jdbcType="VARCHAR" property="formulaExpression" /> <result column="formula_expression" jdbcType="VARCHAR" property="formulaExpression"/>
<result column="data" jdbcType="VARCHAR" property="data" /> <result column="data" jdbcType="VARCHAR" property="data"/>
<result column="data_source_id" jdbcType="BIGINT" property="dataSourceId" /> <result column="data_source_id" jdbcType="BIGINT" property="dataSourceId"/>
<result column="create_by" jdbcType="VARCHAR" property="createBy" /> <result column="create_by" jdbcType="VARCHAR" property="createBy"/>
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
<result column="update_by" jdbcType="VARCHAR" property="updateBy" /> <result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<!-- <!--
...@@ -40,7 +40,8 @@ ...@@ -40,7 +40,8 @@
</when> </when>
<when test="criterion.listValue"> <when test="criterion.listValue">
and ${criterion.condition} and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> <foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem} #{listItem}
</foreach> </foreach>
</when> </when>
...@@ -73,7 +74,8 @@ ...@@ -73,7 +74,8 @@
</when> </when>
<when test="criterion.listValue"> <when test="criterion.listValue">
and ${criterion.condition} and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> <foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem} #{listItem}
</foreach> </foreach>
</when> </when>
...@@ -92,7 +94,8 @@ ...@@ -92,7 +94,8 @@
id, period, report_id, cell_template_id, formula_expression, `data`, data_source_id, id, period, report_id, cell_template_id, formula_expression, `data`, data_source_id,
create_by, create_time, update_by, update_time create_by, create_time, update_by, update_time
</sql> </sql>
<select id="selectByExample" parameterType="pwc.taxtech.atms.vat.entity.PeriodFormulaBlockExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="pwc.taxtech.atms.vat.entity.PeriodFormulaBlockExample"
resultMap="BaseResultMap">
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
...@@ -101,10 +104,10 @@ ...@@ -101,10 +104,10 @@
<if test="distinct"> <if test="distinct">
distinct distinct
</if> </if>
<include refid="Base_Column_List" /> <include refid="Base_Column_List"/>
from period_formula_block from period_formula_block
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause"/>
</if> </if>
<if test="orderByClause != null"> <if test="orderByClause != null">
order by ${orderByClause} order by ${orderByClause}
...@@ -116,7 +119,7 @@ ...@@ -116,7 +119,7 @@
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
--> -->
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List"/>
from period_formula_block from period_formula_block
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</select> </select>
...@@ -135,7 +138,7 @@ ...@@ -135,7 +138,7 @@
--> -->
delete from period_formula_block delete from period_formula_block
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause"/>
</if> </if>
</delete> </delete>
<insert id="insert" parameterType="pwc.taxtech.atms.vat.entity.PeriodFormulaBlock"> <insert id="insert" parameterType="pwc.taxtech.atms.vat.entity.PeriodFormulaBlock">
...@@ -229,14 +232,15 @@ ...@@ -229,14 +232,15 @@
</if> </if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="pwc.taxtech.atms.vat.entity.PeriodFormulaBlockExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="pwc.taxtech.atms.vat.entity.PeriodFormulaBlockExample"
resultType="java.lang.Long">
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
--> -->
select count(*) from period_formula_block select count(*) from period_formula_block
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause"/>
</if> </if>
</select> </select>
<update id="updateByExampleSelective" parameterType="map"> <update id="updateByExampleSelective" parameterType="map">
...@@ -281,7 +285,7 @@ ...@@ -281,7 +285,7 @@
</if> </if>
</set> </set>
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause"/>
</if> </if>
</update> </update>
<update id="updateByExample" parameterType="map"> <update id="updateByExample" parameterType="map">
...@@ -302,7 +306,7 @@ ...@@ -302,7 +306,7 @@
update_by = #{record.updateBy,jdbcType=VARCHAR}, update_by = #{record.updateBy,jdbcType=VARCHAR},
update_time = #{record.updateTime,jdbcType=TIMESTAMP} update_time = #{record.updateTime,jdbcType=TIMESTAMP}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause"/>
</if> </if>
</update> </update>
<update id="updateByPrimaryKeySelective" parameterType="pwc.taxtech.atms.vat.entity.PeriodFormulaBlock"> <update id="updateByPrimaryKeySelective" parameterType="pwc.taxtech.atms.vat.entity.PeriodFormulaBlock">
...@@ -363,7 +367,8 @@ ...@@ -363,7 +367,8 @@
update_time = #{updateTime,jdbcType=TIMESTAMP} update_time = #{updateTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
<select id="selectByExampleWithRowbounds" parameterType="pwc.taxtech.atms.vat.entity.PeriodFormulaBlockExample" resultMap="BaseResultMap"> <select id="selectByExampleWithRowbounds" parameterType="pwc.taxtech.atms.vat.entity.PeriodFormulaBlockExample"
resultMap="BaseResultMap">
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
...@@ -372,13 +377,21 @@ ...@@ -372,13 +377,21 @@
<if test="distinct"> <if test="distinct">
distinct distinct
</if> </if>
<include refid="Base_Column_List" /> <include refid="Base_Column_List"/>
from period_formula_block from period_formula_block
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause"/>
</if> </if>
<if test="orderByClause != null"> <if test="orderByClause != null">
order by ${orderByClause} order by ${orderByClause}
</if> </if>
</select> </select>
<update id="updateReportId">
update period_formula_block
set report_id=#{reportId,jdbcType=BIGINT}
where period=#{period,jdbcType=INTEGER} and cell_template_id in
<foreach collection="cellTemplateConfigIds" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</update>
</mapper> </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