Commit 014ec32d authored by frank.xa.zhang's avatar frank.xa.zhang

add formula parse method

parent 7c46546f
package pwc.taxtech.atms.controller; package pwc.taxtech.atms.controller;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
......
...@@ -35,7 +35,12 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp ...@@ -35,7 +35,12 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp
List<CellTemplateConfigDto> rData = new ArrayList<>(); List<CellTemplateConfigDto> rData = new ArrayList<>();
for (CellTemplate x : cellTemplateList) { for (CellTemplate x : cellTemplateList) {
rData.add(getConfigDto(x, configList.stream().filter(a -> a.getCellTemplateId().equals(x.getId())).collect(Collectors.toList()))); CellTemplateConfigDto cellTemplateConfigDto = getConfigDto(x, configList.stream()
.filter(a -> a.getCellTemplateId().equals(x.getId()))
.collect(Collectors.toList()));
if (cellTemplateConfigDto != null) {
rData.add(cellTemplateConfigDto);
}
} }
if (rData.size() > 0) { if (rData.size() > 0) {
...@@ -118,7 +123,7 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp ...@@ -118,7 +123,7 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp
OperationResultDto<List<CellTemplateConfig>> operationResultDto = new OperationResultDto<>(); OperationResultDto<List<CellTemplateConfig>> operationResultDto = new OperationResultDto<>();
List<CellTemplateConfig> cellTemplateConfigList = new ArrayList<>(); List<CellTemplateConfig> cellTemplateConfigList = new ArrayList<>();
if (cellTemplateConfigDto.getHasFormula()!=null&& cellTemplateConfigDto.getHasFormula()) { if (cellTemplateConfigDto.getHasFormula() != null && cellTemplateConfigDto.getHasFormula()) {
operationResultDto.setResultMsg(getFormulaDataSource(cellTemplateConfigDto.getFormula(), keyValueIds)); operationResultDto.setResultMsg(getFormulaDataSource(cellTemplateConfigDto.getFormula(), keyValueIds));
CellTemplateConfig cellTemplateConfig = new CellTemplateConfig(); CellTemplateConfig cellTemplateConfig = new CellTemplateConfig();
cellTemplateConfig.setId(distributedIDService.nextId()); cellTemplateConfig.setId(distributedIDService.nextId());
...@@ -135,7 +140,7 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp ...@@ -135,7 +140,7 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp
cellTemplateConfigList.add(cellTemplateConfig); cellTemplateConfigList.add(cellTemplateConfig);
} }
if (cellTemplateConfigDto.getHasVoucher()!=null&& cellTemplateConfigDto.getHasVoucher()) { if (cellTemplateConfigDto.getHasVoucher() != null && cellTemplateConfigDto.getHasVoucher()) {
CellTemplateConfig cellTemplateConfig = new CellTemplateConfig(); CellTemplateConfig cellTemplateConfig = new CellTemplateConfig();
cellTemplateConfig.setId(distributedIDService.nextId()); cellTemplateConfig.setId(distributedIDService.nextId());
cellTemplateConfig.setCellTemplateId(cellTemplateConfigDto.getCellTemplateID()); cellTemplateConfig.setCellTemplateId(cellTemplateConfigDto.getCellTemplateID());
...@@ -150,7 +155,7 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp ...@@ -150,7 +155,7 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp
cellTemplateConfigList.add(cellTemplateConfig); cellTemplateConfigList.add(cellTemplateConfig);
} }
if (cellTemplateConfigDto.getHasInvoice()!=null&& cellTemplateConfigDto.getHasInvoice()) { if (cellTemplateConfigDto.getHasInvoice() != null && cellTemplateConfigDto.getHasInvoice()) {
CellTemplateConfig cellTemplateConfig = new CellTemplateConfig(); CellTemplateConfig cellTemplateConfig = new CellTemplateConfig();
cellTemplateConfig.setId(distributedIDService.nextId()); cellTemplateConfig.setId(distributedIDService.nextId());
cellTemplateConfig.setCellTemplateId(cellTemplateConfigDto.getCellTemplateID()); cellTemplateConfig.setCellTemplateId(cellTemplateConfigDto.getCellTemplateID());
...@@ -167,7 +172,7 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp ...@@ -167,7 +172,7 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp
cellTemplateConfigList.add(cellTemplateConfig); cellTemplateConfigList.add(cellTemplateConfig);
} }
if (cellTemplateConfigDto.getHasKeyIn()!=null&& cellTemplateConfigDto.getHasKeyIn()) { if (cellTemplateConfigDto.getHasKeyIn() != null && cellTemplateConfigDto.getHasKeyIn()) {
CellTemplateConfig cellTemplateConfig = new CellTemplateConfig(); CellTemplateConfig cellTemplateConfig = new CellTemplateConfig();
cellTemplateConfig.setId(distributedIDService.nextId()); cellTemplateConfig.setId(distributedIDService.nextId());
cellTemplateConfig.setCellTemplateId(cellTemplateConfigDto.getCellTemplateID()); cellTemplateConfig.setCellTemplateId(cellTemplateConfigDto.getCellTemplateID());
...@@ -180,7 +185,7 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp ...@@ -180,7 +185,7 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp
cellTemplateConfigList.add(cellTemplateConfig); cellTemplateConfigList.add(cellTemplateConfig);
} }
if (cellTemplateConfigDto.getHasModel()!=null&& cellTemplateConfigDto.getHasModel()) { if (cellTemplateConfigDto.getHasModel() != null && cellTemplateConfigDto.getHasModel()) {
CellTemplateConfig cellTemplateConfig = new CellTemplateConfig(); CellTemplateConfig cellTemplateConfig = new CellTemplateConfig();
cellTemplateConfig.setId(distributedIDService.nextId()); cellTemplateConfig.setId(distributedIDService.nextId());
cellTemplateConfig.setCellTemplateId(cellTemplateConfigDto.getCellTemplateID()); cellTemplateConfig.setCellTemplateId(cellTemplateConfigDto.getCellTemplateID());
...@@ -194,7 +199,7 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp ...@@ -194,7 +199,7 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp
cellTemplateConfigList.add(cellTemplateConfig); cellTemplateConfigList.add(cellTemplateConfig);
} }
if (cellTemplateConfigDto.getHasValidation()!=null&& cellTemplateConfigDto.getHasValidation()) { if (cellTemplateConfigDto.getHasValidation() != null && cellTemplateConfigDto.getHasValidation()) {
CellTemplateConfig cellTemplateConfig = new CellTemplateConfig(); CellTemplateConfig cellTemplateConfig = new CellTemplateConfig();
cellTemplateConfig.setId(distributedIDService.nextId()); cellTemplateConfig.setId(distributedIDService.nextId());
cellTemplateConfig.setCellTemplateId(cellTemplateConfigDto.getCellTemplateID()); cellTemplateConfig.setCellTemplateId(cellTemplateConfigDto.getCellTemplateID());
...@@ -287,6 +292,7 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp ...@@ -287,6 +292,7 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp
private CellTemplateConfigDto getConfigDto(CellTemplate cellTemplate, List<CellTemplateConfig> configList) { private CellTemplateConfigDto getConfigDto(CellTemplate cellTemplate, List<CellTemplateConfig> configList) {
CellTemplateConfigDto cellTemplateConfigDto = CellConfigTranslater.getConfigDto(cellTemplate, configList); CellTemplateConfigDto cellTemplateConfigDto = CellConfigTranslater.getConfigDto(cellTemplate, configList);
if (cellTemplateConfigDto != null) {
cellTemplateConfigDto.setCellTemplateID(cellTemplate.getId()); cellTemplateConfigDto.setCellTemplateID(cellTemplate.getId());
cellTemplateConfigDto.setTemplateID(cellTemplate.getReportTemplateId()); cellTemplateConfigDto.setTemplateID(cellTemplate.getReportTemplateId());
cellTemplateConfigDto.setRowIndex(cellTemplate.getRowIndex()); cellTemplateConfigDto.setRowIndex(cellTemplate.getRowIndex());
...@@ -298,4 +304,6 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp ...@@ -298,4 +304,6 @@ public class CellTemplateServiceImpl extends AbstractService implements CellTemp
cellTemplateConfigDto.setFormulaDescription(cellTemplate.getComment()); cellTemplateConfigDto.setFormulaDescription(cellTemplate.getComment());
return cellTemplateConfigDto; return cellTemplateConfigDto;
} }
return null;
}
} }
...@@ -111,7 +111,7 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat ...@@ -111,7 +111,7 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat
} }
@Override @Override
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class) @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public OperationResultDto<Object> deleteTemplateGroup(TemplateGroupDto templateGroupDto) { public OperationResultDto<Object> deleteTemplateGroup(TemplateGroupDto templateGroupDto) {
OperationResultDto<Object> result = new OperationResultDto<>(); OperationResultDto<Object> result = new OperationResultDto<>();
TemplateGroup templateGroupDb = templateGroupMapper.selectByPrimaryKey(templateGroupDto.getId()); TemplateGroup templateGroupDb = templateGroupMapper.selectByPrimaryKey(templateGroupDto.getId());
...@@ -134,7 +134,7 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat ...@@ -134,7 +134,7 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat
List<String> pathList = new ArrayList<>(); List<String> pathList = new ArrayList<>();
for (Template templateDb : templateDbList) { for (Template templateDb : templateDbList) {
boolean anySameCodeExists = allTemplateDbList.stream().anyMatch(a -> a.getCode()==templateDb.getCode() && a.getName()==templateDb.getCode()); boolean anySameCodeExists = allTemplateDbList.stream().anyMatch(a -> a.getCode() == templateDb.getCode() && a.getName() == templateDb.getCode());
if (!anySameCodeExists) { if (!anySameCodeExists) {
pathList.add((templateDb.getPath())); pathList.add((templateDb.getPath()));
...@@ -257,18 +257,18 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat ...@@ -257,18 +257,18 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat
} }
cellTemplate.setIsReadOnly(cell.getCellStyle().getLocked()); cellTemplate.setIsReadOnly(cell.getCellStyle().getLocked());
cellTemplateList.add(cellTemplate); cellTemplateList.add(cellTemplate);
//todo: 这里没有Config数据只有在上传模板以后,在界面里面可以配置公式
CellTemplateConfig config = new CellTemplateConfig(); // CellTemplateConfig config = new CellTemplateConfig();
config.setId(distributedIDService.nextId()); // config.setId(distributedIDService.nextId());
config.setCellTemplateId(cellTemplate.getId()); // config.setCellTemplateId(cellTemplate.getId());
config.setReportTemplateId(template.getId()); // config.setReportTemplateId(template.getId());
config.setDataSourceType(1);//todo 枚举 // config.setDataSourceType(1);//todo 枚举
config.setFormula(POIUtil.getCellFormulaString(cell)); // config.setFormula(POIUtil.getCellFormulaString(cell));
//config.setFormula(cell.getCellFormula()); // //config.setFormula(cell.getCellFormula());
// config.setFormulaDataSource(); //todo KV相关 //// config.setFormulaDataSource(); //todo KV相关
config.setUpdateTime(now); // config.setUpdateTime(now);
config.setUpdateBy(authUserHelper.getCurrentUserID()); // config.setUpdateBy(authUserHelper.getCurrentUserID());
cellTemplateConfigList.add(config); // cellTemplateConfigList.add(config);
} }
} }
List<List<CellTemplate>> tmpList = CommonUtils.subListWithLen(cellTemplateList, CommonUtils.BATCH_NUM); List<List<CellTemplate>> tmpList = CommonUtils.subListWithLen(cellTemplateList, CommonUtils.BATCH_NUM);
...@@ -349,17 +349,17 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat ...@@ -349,17 +349,17 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat
} }
cellTemplate.setIsReadOnly(cell.getCellStyle().getLocked() ? true : false); cellTemplate.setIsReadOnly(cell.getCellStyle().getLocked() ? true : false);
cellTemplateList.add(cellTemplate); cellTemplateList.add(cellTemplate);
//todo: 这里没有Config数据只有在上传模板以后,在界面里面可以配置公式
CellTemplateConfig config = new CellTemplateConfig(); // CellTemplateConfig config = new CellTemplateConfig();
config.setId(distributedIDService.nextId()); // config.setId(distributedIDService.nextId());
config.setCellTemplateId(cellTemplate.getId()); // config.setCellTemplateId(cellTemplate.getId());
config.setReportTemplateId(template.getId()); // config.setReportTemplateId(template.getId());
config.setDataSourceType(1);//todo 枚举 // config.setDataSourceType(1);//todo 枚举
config.setFormula(POIUtil.getCellFormulaString(cell)); // config.setFormula(POIUtil.getCellFormulaString(cell));
// config.setFormulaDataSource(); //todo KV相关 //// config.setFormulaDataSource(); //todo KV相关
config.setUpdateTime(now); // config.setUpdateTime(now);
config.setUpdateBy(authUserHelper.getCurrentUserID()); // config.setUpdateBy(authUserHelper.getCurrentUserID());
cellTemplateConfigList.add(config); // cellTemplateConfigList.add(config);
} }
} }
List<List<CellTemplate>> tmpList = CommonUtils.subListWithLen(cellTemplateList, CommonUtils.BATCH_NUM); List<List<CellTemplate>> tmpList = CommonUtils.subListWithLen(cellTemplateList, CommonUtils.BATCH_NUM);
......
...@@ -27,6 +27,8 @@ import java.io.File; ...@@ -27,6 +27,8 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.*; import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static pwc.taxtech.atms.constant.Constant.EMPTY; import static pwc.taxtech.atms.constant.Constant.EMPTY;
...@@ -59,12 +61,12 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen ...@@ -59,12 +61,12 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
Long templateGroupID = periodTemplateList.size() > 0 ? periodTemplateList.get(0).getTemplateGroupId() : 0; Long templateGroupID = periodTemplateList.size() > 0 ? periodTemplateList.get(0).getTemplateGroupId() : 0;
PeriodCellTemplateExample periodCellTemplateExample = new PeriodCellTemplateExample(); PeriodCellTemplateExample periodCellTemplateExample = new PeriodCellTemplateExample();
periodCellTemplateExample.createCriteria().andReportTemplateIdIn(periodTemplateIDList); periodCellTemplateExample.createCriteria().andReportTemplateIdIn(periodTemplateIDList).andPeriodEqualTo(period);
List<PeriodCellTemplate> periodCellTemplateList = periodCellTemplateMapper.selectByExample(periodCellTemplateExample); List<PeriodCellTemplate> periodCellTemplateList = periodCellTemplateMapper.selectByExample(periodCellTemplateExample);
PeriodCellTemplateConfigExample periodCellTemplateConfigExample = new PeriodCellTemplateConfigExample(); PeriodCellTemplateConfigExample periodCellTemplateConfigExample = new PeriodCellTemplateConfigExample();
// only get formula config // only get formula config
periodCellTemplateConfigExample.createCriteria().andReportTemplateIdIn(periodTemplateIDList); periodCellTemplateConfigExample.createCriteria().andReportTemplateIdIn(periodTemplateIDList).andPeriodEqualTo(period);
List<PeriodCellTemplateConfig> periodCellTemplateConfigList = List<PeriodCellTemplateConfig> periodCellTemplateConfigList =
periodCellTemplateConfigMapper.selectByExample(periodCellTemplateConfigExample); periodCellTemplateConfigMapper.selectByExample(periodCellTemplateConfigExample);
...@@ -174,9 +176,21 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen ...@@ -174,9 +176,21 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
List<Long> cellTemplateConfigIds = periodCellTemplateConfigs.stream() List<Long> cellTemplateConfigIds = periodCellTemplateConfigs.stream()
.map(PeriodCellTemplateConfig::getCellTemplateId) .map(PeriodCellTemplateConfig::getCellTemplateId)
.collect(Collectors.toList()); .collect(Collectors.toList());
if (cellTemplateConfigIds.size() > 0) {
periodFormulaBlockMapper.updateReportId(reportID, cellTemplateConfigIds, period); periodFormulaBlockMapper.updateReportId(reportID, cellTemplateConfigIds, period);
}
for (PeriodCellTemplateConfig periodCellTemplateConfig : periodCellTemplateConfigs) { for (PeriodCellTemplateConfig periodCellTemplateConfig : periodCellTemplateConfigs) {
//TODO:如果formula 为 ND(100) +ND(22) ,需要使用正则表达式拆分出自定义公式,然后根据自定义公式取formulablock 的数据进行替换
String regex = "[A-Z]*\\([A-Za-z0-9\\\"\\,\\.\\u4e00-\\u9fa5\\%]*\\)";
Pattern p = Pattern.compile( regex );
Matcher m = p.matcher(periodCellTemplateConfig.getFormula());
while( m.find() )
{
//如果有些公式无法用正则匹配,可以做特殊处理
//System.out.println( "匹配项" + count+":" + m.group() ); //group方法返回由以前匹配操作所匹配的输入子序列。
}
Optional<PeriodCellTemplate> tempPeriodCellTemplate = periodCellTemplateList.stream() Optional<PeriodCellTemplate> tempPeriodCellTemplate = periodCellTemplateList.stream()
.filter(a -> a.getCellTemplateId().equals(periodCellTemplateConfig.getCellTemplateId())) .filter(a -> a.getCellTemplateId().equals(periodCellTemplateConfig.getCellTemplateId()))
.findFirst(); .findFirst();
......
...@@ -1335,7 +1335,6 @@ ng-show="hasEditPermission && ToggleSaveAs && editModel.hasModel"/>'); ...@@ -1335,7 +1335,6 @@ ng-show="hasEditPermission && ToggleSaveAs && editModel.hasModel"/>');
}; };
/*********************** End Formula Editor ***********************************/ /*********************** End Formula Editor ***********************************/
//模板另存为 //模板另存为
var saveTemplateGroup = function () { var saveTemplateGroup = function () {
var groupName = $scope.groupName; var groupName = $scope.groupName;
......
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