Commit ebc495dd authored by zhkwei's avatar zhkwei

1、BB公式修改;2、CIT-固定资产导入部分性能优化;3、CIT-数据处理增加CIT的正则表达式

parent 428577c0
......@@ -254,9 +254,6 @@ public class AssetListServiceImpl extends BaseService {
}
//循环存储新的资产
int insertBatch = assetListMapper.insertBatch(citAssetsLists);
// for (CitAssetsList citAsset : citAssetsLists){
// assetListMapper.insertSelective(citAsset);
// }
//处理资产类别
//1、根据projectId查询数据库中已有的资产类别,并和新导入的资产类别进行比较
// for (CitAssetGroupResult groupResult : citAssetGroupResults) {
......@@ -428,6 +425,8 @@ public class AssetListServiceImpl extends BaseService {
List<CitAssetsList> citAssetsLists = selectAssetsList(projectId, assetGroupResult.getAssetName(),saveGroupType);
citAssetsLists.stream().forEach(citAsset -> {
setCitAssetTaxData(citAsset,assetGroupResult,assetDetailGroup);
//根据主键修改资产清单数据
assetListMapper.updateByPrimaryKeySelective(citAsset);
});
}
......@@ -494,7 +493,7 @@ public class AssetListServiceImpl extends BaseService {
//更改资产状态,已进行分类并有效
citAsset.setStatus(1);
//根据主键修改资产清单数据
assetListMapper.updateByPrimaryKeySelective(citAsset);
// assetListMapper.updateByPrimaryKeySelective(citAsset);
}
public ApiResultDto updateAssetResultList(List<CitAssetsList> assetsLists, String projectId){
......
......@@ -234,7 +234,7 @@ public class CitReportServiceImpl extends BaseService {
setStatus(genJob, STATUS_END);
periodJobMapper.updateByPrimaryKey(genJob);
reportGenerator.updateWorkbookCaclsValueToDb(projectId, periodParam, workbook, resources, isMergeManualData, genJob);
reportGenerator.citUpdateWorkbookCaclsValueToDb(projectId, periodParam, workbook, resources, isMergeManualData, genJob);
//===============================================start validation compute==========================================================
//todo: 1.get the data from workbook, then put the data into new workbook
......
......@@ -108,6 +108,21 @@ public class FormulaAgent {
}
/**
* 查询所有的数据源,来用作判断当前单元格是只有手工数据源还是还有别的数据源 create by zhikai.z.wei at 20190411 20:44
* @param templateId
* @param projectId
* @param period
* @return
*/
public List<PeriodDataSource> queryNoManualDataSource(Long templateId, String projectId, Integer period) {
PeriodDataSourceExample example = new PeriodDataSourceExample();
example.createCriteria().andProjectIdEqualTo(projectId).andPeriodEqualTo(period)
.andCellTemplateIdEqualTo(templateId);
return periodDataSourceMapper.selectByExample(example);
}
private PeriodReport getReportByTemplate(String templateId, Integer periodId, String projectId) {
PeriodReportExample example = new PeriodReportExample();
example.createCriteria().andProjectIdEqualTo(projectId).andTemplateIdEqualTo(Long.valueOf(templateId))
......
......@@ -327,6 +327,252 @@ public class ReportGeneratorImpl {
}
}
/**
* create by zhikai.z.wei 更改正则表达式,匹配E13-D13这种公式,要不然此单元格设置为允许手工数据后页面不能计算出实际值
* @param projectId
* @param period
* @param workbook
* @param resources
* @param isMergeMunual
* @param job
*/
public void citUpdateWorkbookCaclsValueToDb(String projectId, Integer period, Workbook workbook, PeriodResources resources,
Boolean isMergeMunual, PeriodJob job) {
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
Sheet sheet = workbook.getSheetAt(i);
String code = sheet.getSheetName();
logger.info("-------------------------------------Begin Job [{}]------------------------------------------------------", code);
setStatus(job, STATUS_END);
setStatus(job, code, STATUS_BEGIN);
job.setCurrentStep(code);
periodJobMapper.updateByPrimaryKey(job);
Optional<PeriodTemplate> periodTemplate = resources.getPeriodTemplates().stream()
.filter(a -> a.getCode().equals(code))
.findFirst();
Long templateId;
if (periodTemplate.isPresent()) {
templateId = periodTemplate.get().getTemplateId();
} else {
templateId = 0L;
}
if (templateId > 0) {
PeriodReport report = new PeriodReport();
Long reportId = distributedIdService.nextId();
report.setId(reportId);
report.setTemplateId(templateId);
report.setPeriod(period);
report.setProjectId(projectId);
report.setCreateBy("Admin");
report.setCreateTime(new Date());
report.setUpdateBy("Admin");
report.setUpdateTime(new Date());
report.setProjectId(projectId);
reportMapper.insertSelective(report);
List<PeriodCellTemplateConfig> periodCellTemplateConfigs = resources.getPeriodCellTemplateConfigs().stream()
.filter(a -> a.getReportTemplateId().equals(templateId) && a.getDataSourceType().equals(CellDataSourceType.Formula.getCode()))
.collect(Collectors.toList());
//update formulablock table reportid field
List<Long> cellTemplateConfigIds = periodCellTemplateConfigs.stream()
.map(PeriodCellTemplateConfig::getCellTemplateId)
.collect(Collectors.toList());
if (cellTemplateConfigIds.size() > 0) {
periodFormulaBlockMapper.updateReportId(reportId, cellTemplateConfigIds, period, projectId);
}
for (PeriodCellTemplateConfig periodCellTemplateConfig : periodCellTemplateConfigs) {
PeriodFormulaBlockExample periodFormulaBlockExample2 = new PeriodFormulaBlockExample();
periodFormulaBlockExample2.createCriteria()
.andProjectIdEqualTo(projectId)
.andCellTemplateIdEqualTo(periodCellTemplateConfig.getCellTemplateId())
.andReportIdEqualTo(reportId)
.andPeriodEqualTo(period);
List<PeriodFormulaBlock> periodFormulaBlocks = periodFormulaBlockMapper.selectByExample(periodFormulaBlockExample2);
//TODO:如果formula 为 ND(100) +ND(22) ,需要使用正则表达式拆分出自定义公式,然后根据自定义公式取formulablock 的数据进行替换
// String regex = "[A-Z]*\\([\\-A-Za-z0-9\\\"\\,\\.\\:\\u4e00-\\u9fa5\\%]*\\)";
String regex = "([A-Z]*\\([^(^)]*\\))|(([A-Z]*[0-9]*((\\+|\\-|\\*|\\/))*)*)";
Pattern p = Pattern.compile(regex);
String sourceFormula = StringUtils.isNotBlank(periodCellTemplateConfig.getKeyValueParsedFormula()) ?
periodCellTemplateConfig.getKeyValueParsedFormula() :
periodCellTemplateConfig.getFormula();
String resultFormula = StringUtils.isNotBlank(periodCellTemplateConfig.getKeyValueParsedFormula()) ?
periodCellTemplateConfig.getKeyValueParsedFormula() :
periodCellTemplateConfig.getFormula();
Matcher m = p.matcher(sourceFormula);
Boolean isFind = false;
while (m.find()) {
isFind = true;
//如果有些公式无法用正则匹配,可以做特殊处理
String findStr = m.group();
Optional<PeriodFormulaBlock> formulaBlock = periodFormulaBlocks.stream()
.filter(a -> a.getFormulaExpression().equals(findStr))
.findFirst();
if (formulaBlock.isPresent()) {
resultFormula = resultFormula.replace(findStr, formulaBlock.get().getData());
}
}
//如果有正则匹配就进行更新公式解析
if (isFind) {
periodCellTemplateConfig.setParsedFormula(StringUtils.isNotBlank(resultFormula) ? resultFormula : null);
periodCellTemplateConfigMapper.updateByPrimaryKeySelective(periodCellTemplateConfig);
}
Optional<PeriodCellTemplate> tempPeriodCellTemplate = resources.getPeriodCellTemplates().stream()
.filter(a -> a.getCellTemplateId().equals(periodCellTemplateConfig.getCellTemplateId()))
.findFirst();
if (tempPeriodCellTemplate.isPresent()) {
PeriodCellData cellData = new PeriodCellData();
Long cellDataId = distributedIdService.nextId();
cellData.setId(cellDataId);
cellData.setReportId(reportId);
cellData.setCellTemplateId(tempPeriodCellTemplate.get().getCellTemplateId());
String data;
if (sheet.getRow(tempPeriodCellTemplate.get().getRowIndex()) != null
&& sheet.getRow(tempPeriodCellTemplate.get().getRowIndex())
.getCell(tempPeriodCellTemplate.get().getColumnIndex()) != null) {
Cell cell = sheet.getRow(tempPeriodCellTemplate.get().getRowIndex())
.getCell(tempPeriodCellTemplate.get().getColumnIndex());
data = ((XSSFCell) cell).getRawValue();
if (data != null && data.equals("#VALUE!")) {
FormulaEvaluator formulaEvaluator = new XSSFFormulaEvaluator((XSSFWorkbook) workbook);
try {
data = formulaEvaluator.evaluate(cell).getStringValue();
} catch (Exception e) {
logger.error(e.getStackTrace().toString());
data = "0.0";
}
}
} else {
data = "0.0";
}
if (StringUtils.isNotBlank(data)) {
Pattern pattern = Pattern.compile("[0-9.]*");
Matcher isNum = pattern.matcher(data);
if (isNum.matches()) {
cellData.setData(new BigDecimal(data).toString());
} else {
cellData.setData(data);
}
} else {
cellData.setData(data);
}
if (StringUtils.isBlank(resultFormula)) {
resultFormula = " ";
}
cellData.setFormulaExp(resultFormula);
cellData.setCreateBy("Admin");
cellData.setCreateTime(new Date());
cellData.setUpdateBy("Admin");
cellData.setUpdateTime(new Date());
cellData.setProjectId(projectId);
cellData.setPeriod(period);
//after insert celldata, insert the celldatasource for link celldata and datasource
PeriodDataSourceExample dataSourceExample = new PeriodDataSourceExample();
dataSourceExample.createCriteria().andPeriodEqualTo(period).andProjectIdEqualTo(projectId)
.andCellTemplateIdEqualTo(tempPeriodCellTemplate.get().getCellTemplateId()).andTypeNotEqualTo(10);
List<PeriodDataSource> dataSourceList = SpringContextUtil.periodDataSourceMapper.selectByExample(dataSourceExample);
for (int ii = 0; ii < dataSourceList.size(); ii++) {
PeriodDataSource dataSource = dataSourceList.get(ii);
PeriodCellDataSource cellDataSource = new PeriodCellDataSource();
cellDataSource.setId(distributedIdService.nextId());
cellDataSource.setCellTemplateId(tempPeriodCellTemplate.get().getCellTemplateId());
cellDataSource.setCellDataId(cellDataId);
cellDataSource.setDataSourceId(dataSource.getId());
cellDataSource.setCreateTime(new Date());
cellDataSource.setUpdateTime(new Date());
cellDataSource.setPeriod(period);
cellDataSource.setProjectId(projectId);
SpringContextUtil.periodCellDataSourceMapper.insertSelective(cellDataSource);
}
periodCellDataMapper.insertSelective(cellData);
}
}
if (isMergeMunual) {
List<PeriodCellTemplateConfig> keyInCellTemplateConfigs = resources.getPeriodCellTemplateConfigs().stream()
.filter(a -> a.getReportTemplateId().equals(templateId) && a.getDataSourceType().equals(CellDataSourceType.KeyIn.getCode()))
.collect(Collectors.toList());
for (PeriodCellTemplateConfig keyInCellTemplateConfig : keyInCellTemplateConfigs) {
PeriodDataSourceExample dataSourceExample = new PeriodDataSourceExample();
dataSourceExample.createCriteria().andPeriodEqualTo(period).andProjectIdEqualTo(projectId)
.andCellTemplateIdEqualTo(keyInCellTemplateConfig.getCellTemplateId()).andTypeEqualTo(10);
List<PeriodDataSource> dataSourceList = SpringContextUtil.periodDataSourceMapper.selectByExample(dataSourceExample);
if (!dataSourceList.isEmpty() && dataSourceList.size() == 1) {
PeriodCellDataExample cellDataExample = new PeriodCellDataExample();
cellDataExample.createCriteria().andPeriodEqualTo(period).andProjectIdEqualTo(projectId)
.andCellTemplateIdEqualTo(keyInCellTemplateConfig.getCellTemplateId());
List<PeriodCellData> cellDataList = periodCellDataMapper.selectByExample(cellDataExample);
if (cellDataList.size() == 1) {
PeriodCellData cellData = cellDataList.get(0);
PeriodDataSource dataSource = dataSourceList.get(0);
if (StringUtils.isEmpty(cellData.getData().trim()))
cellData.setData("0.0");
if (StringUtils.isEmpty(cellData.getFormulaExp().trim()))
cellData.setFormulaExp("0.0");
PeriodCellDataSource cellDataSource = new PeriodCellDataSource();
cellDataSource.setId(distributedIdService.nextId());
cellDataSource.setCellTemplateId(keyInCellTemplateConfig.getCellTemplateId());
cellDataSource.setCellDataId(cellData.getId());
cellDataSource.setDataSourceId(dataSource.getId());
cellDataSource.setCreateTime(new Date());
cellDataSource.setUpdateTime(new Date());
cellDataSource.setPeriod(period);
cellDataSource.setProjectId(projectId);
SpringContextUtil.periodCellDataSourceMapper.insertSelective(cellDataSource);
periodCellDataMapper.updateByPrimaryKeySelective(cellData);
} else if (cellDataList.isEmpty()) {
PeriodCellData cellData = new PeriodCellData();
Long cellDataId = distributedIdService.nextId();
cellData.setId(cellDataId);
cellData.setReportId(reportId);
cellData.setCellTemplateId(keyInCellTemplateConfig.getCellTemplateId());
cellData.setCreateBy("Admin");
cellData.setCreateTime(new Date());
cellData.setUpdateBy("Admin");
cellData.setUpdateTime(new Date());
cellData.setProjectId(projectId);
cellData.setPeriod(period);
PeriodDataSource dataSource = dataSourceList.get(0);
cellData.setData("0.0");
cellData.setFormulaExp("0.0");
PeriodCellDataSource cellDataSource = new PeriodCellDataSource();
cellDataSource.setId(distributedIdService.nextId());
cellDataSource.setCellTemplateId(keyInCellTemplateConfig.getCellTemplateId());
cellDataSource.setCellDataId(cellData.getId());
cellDataSource.setDataSourceId(dataSource.getId());
cellDataSource.setCreateTime(new Date());
cellDataSource.setUpdateTime(new Date());
cellDataSource.setPeriod(period);
cellDataSource.setProjectId(projectId);
SpringContextUtil.periodCellDataSourceMapper.insertSelective(cellDataSource);
periodCellDataMapper.insertSelective(cellData);
} else {
logger.warn("should not be !!!");
}
}
}
}
}
logger.info("-------------------------------------End Job [{}]------------------------------------------------------", code);
}
}
private List<PeriodReport> createReportsByTemplates(Workbook
workbook, List<PeriodTemplate> periodTemplateList, String projectId, Integer period) {
List<PeriodReport> reports = new ArrayList<>();
......
......@@ -125,8 +125,16 @@ public class BB extends FunctionBase implements FreeRefFunction {
cellValue = new BigDecimal(cellData.getData()).setScale(4,
BigDecimal.ROUND_HALF_DOWN);
} else if (cellData.getData() != null && !dss.isEmpty()) {
cellValue = dss.get(0).getAmount().add(new BigDecimal(cellData.getData()).setScale(4,
BigDecimal.ROUND_HALF_DOWN));
//查询所有的数据源,来用作判断当前单元格是只有手工数据源还是还有别的数据源 create by zhikai.z.wei at 20190411 20:44
List<PeriodDataSource> allDataSource = agent.queryNoManualDataSource(Long.parseLong(cellTemplateData.getCellTemplateId()),
project == null ? formulaContext.getProjectId() : project.getId(), curPeriod.getCurPeriod());
if(!allDataSource.isEmpty() && allDataSource.size()>1){
cellValue = dss.get(0).getAmount().add(new BigDecimal(cellData.getData()).setScale(4,
BigDecimal.ROUND_HALF_DOWN));
}else{
cellValue = new BigDecimal(cellData.getData()).setScale(4,
BigDecimal.ROUND_HALF_DOWN);
}
} else throw Exceptions.BB_CELL_DATA_NULL;
nullCellDto.setAmount(cellValue);
if (rootBo != null) {
......
......@@ -504,6 +504,7 @@
// 根据已有信息通过spreadJS计算各单元格的值
var setData = function () {
debugger;
var sheet = scope.spread.sheets[0];
var isExportData = false;
if (angular.isArray(scope.reportSource)) {
......
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