Commit 285799ae authored by sherlock's avatar sherlock

Merge branches 'dev_oracle' and 'dev_oracle_sherlock' of…

Merge branches 'dev_oracle' and 'dev_oracle_sherlock' of http://code.tech.tax.asia.pwcinternal.com/root/atms into dev_oracle_sherlock
parents 1d2cb258 b3991e25
......@@ -147,7 +147,7 @@ public class ReportGeneratorImpl {
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-Za-z0-9\\\"\\,\\.\\:\\u4e00-\\u9fa5\\%]*\\)";
Pattern p = Pattern.compile(regex);
String sourceFormula = StringUtils.isNotBlank(periodCellTemplateConfig.getKeyValueParsedFormula()) ?
periodCellTemplateConfig.getKeyValueParsedFormula() :
......@@ -172,65 +172,12 @@ public class ReportGeneratorImpl {
//如果有正则匹配就进行更新公式解析
if (isFind) {
periodCellTemplateConfig.setParsedFormula(StringUtils.isNotBlank(resultFormula) ? resultFormula : null);
if (periodCellTemplateConfig.getFormula() != null && !periodCellTemplateConfig.getFormula().contains("BB("))
if (periodCellTemplateConfig.getFormula() != null && (!periodCellTemplateConfig.getFormula().contains("BB(")
||!periodCellTemplateConfig.getFormula().contains("PSUM(")))
periodCellTemplateConfig.setFormula(StringUtils.isNotBlank(periodCellTemplateConfig.getFormula()) ? resultFormula : null);
periodCellTemplateConfigMapper.updateByPrimaryKeySelective(periodCellTemplateConfig);
}
String regexNormalCell = "[A-Z]{1,2}((?!0)[0-9]{1,3})";// todo 这里原生引用计算废弃,改用BB
p = Pattern.compile(regexNormalCell);
m = p.matcher(sourceFormula);
while (m.find()) {
//如果找到普通单元格的公式,就去workbook里查找对应的格子取数据,然后放到DataSource,作为普通单元格数据源的数据
//找到一个格子就加一条数据
String findStr = m.group();//A12,A13,A15,how to get A and 12 or A and 13
String regexColumn = "[A-Z]{1,2}";
Pattern pp = Pattern.compile(regexColumn);
Matcher mm = pp.matcher(findStr);
while (mm.find()) {
String colStr = mm.group();
int colNum = FormulaHelper.excelColStrToNum(colStr, colStr.length());
int rowNum = Integer.parseInt(StringUtils.removeStart(findStr, colStr));
Row row = sheet.getRow(rowNum - 1);
if (row != null) {
Cell cell = row.getCell(colNum - 1);
if (cell != null) {
//开始取值然后存放到DataSource
PeriodDataSource dataSource = new PeriodDataSource();
dataSource.setId(distributedIdService.nextId());
dataSource.setColumnIndex(colNum - 1);
dataSource.setRowIndex(rowNum - 1);
if (((XSSFCell) cell).getRawValue() != "#VALUE!") {
dataSource.setAmount(new BigDecimal(
((XSSFCell) cell).getRawValue() != null ?
((XSSFCell) cell).getRawValue()
: (StringUtils.isNotBlank(cell.getStringCellValue())) ?
cell.getStringCellValue()
: Double.toString(cell.getNumericCellValue())));
} else {
dataSource.setAmount(new BigDecimal("0.0"));
}
dataSource.setName("ReportDataSource");
dataSource.setDescription(findStr);
dataSource.setCreateTime(new Date());
dataSource.setUpdateTime(new Date());
dataSource.setCreateBy("Admin");
dataSource.setUpdateBy("Admin");
dataSource.setPeriod(period);
dataSource.setCellTemplateId(periodCellTemplateConfig.getCellTemplateId());
dataSource.setType(FormulaDataSourceType.Report.getCode());
dataSource.setProjectId(projectId);
periodDataSourceMapper.insertSelective(dataSource);
//这里有个问题就是DataSource的数据有了,但是celldatasource的数据没有,后面无法关联celldata和DataSource
//解决办法就是 在存DataSource的时候就先把celldata的数据加好
//然后把celldatasource的数据也加好
//然后在外面去更新celldata和celldatasource的数据
//还有就是把公式里的数据源放到内存,在所有算完之后再统一加数据源
}
}
}
}
Optional<PeriodCellTemplate> tempPeriodCellTemplate = resources.getPeriodCellTemplates().stream()
.filter(a -> a.getCellTemplateId().equals(periodCellTemplateConfig.getCellTemplateId()))
.findFirst();
......
......@@ -95,39 +95,8 @@ public class BB extends FunctionBase implements FreeRefFunction {
return returnEval;
} else if (bo.getPeriod().intValue() == 0) {
Field evaluatorField = OperationEvaluationContext.class.getDeclaredField("_bookEvaluator");
evaluatorField.setAccessible(true);
WorkbookEvaluator evaluator = (WorkbookEvaluator) evaluatorField.get(ec);
int index = ec.getWorkbook().getSheetIndex(bo.getReportCode());
if (index < 0)
logger.warn("[BB_Exception] not found sheet code {} with {}", bo.getReportCode(), bo.toString());
ValueEval eval = evaluator.evaluate(ec.getWorkbook().getSheet(index)
.getCell(bo.getRowIndex() - 1, bo.getColumnIndex() - 1));
bo.putPeriodCellTempate(formulaContext.getPeriod(), Long.parseLong(cellTemplateData.getCellTemplateId()));
List<PeriodDataSource> dss = agent.queryManualDataSource(Long.parseLong(cellTemplateData.getCellTemplateId()),
formulaContext.getProjectId(), formulaContext.getPeriod());
if (eval instanceof ErrorEval || eval == null || eval instanceof BlankEval) {
LOGGER.warn("[BB_Exception] error eval for bb {} and error code {} and error String {}", bo.toString(),
((ErrorEval) eval).getErrorCode(), ((ErrorEval) eval).getErrorString());
if (!dss.isEmpty()) cellValue = dss.get(0).getAmount();
} else {
String evalStr = OperandResolver.coerceValueToString(eval);
logger.debug("[BB_debug] eval other cell value {}", evalStr);
try {
cellValue = new BigDecimal(evalStr).setScale(4,
BigDecimal.ROUND_HALF_DOWN);
if (!dss.isEmpty())
cellValue = cellValue.add(dss.get(0).getAmount());
} catch (Exception e) {
if (!dss.isEmpty())
cellValue = dss.get(0).getAmount();
else throw e;
}
}
cellValue = getCellValue(ec, formulaContext, agent, bo.getRowIndex() - 1, bo.getColumnIndex() - 1,
Long.parseLong(cellTemplateData.getCellTemplateId()));
nullCellDto.extractFromGroup(bo, formulaContext.getPeriod(), formulaContext.getYear(), cellTemplateData);
nullCellDto.setAmount(cellValue);
......
......@@ -2,19 +2,22 @@ package pwc.taxtech.atms.vat.service.impl.report.functions;
import com.alibaba.fastjson.JSON;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.OperandResolver;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.WorkbookEvaluator;
import org.apache.poi.ss.formula.eval.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pwc.taxtech.atms.common.util.MyAsserts;
import pwc.taxtech.atms.common.util.SpringContextUtil;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceType;
import pwc.taxtech.atms.dpo.CellTemplatePerGroupDto;
import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.vat.entity.PeriodDataSource;
import pwc.taxtech.atms.vat.entity.PeriodDataSourceDetail;
import pwc.taxtech.atms.vat.entity.PeriodFormulaBlock;
import pwc.taxtech.atms.vat.service.impl.FormulaAgent;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
......@@ -27,6 +30,7 @@ public class FunctionBase {
public static final BigDecimal[] defaultTaxRates = {new BigDecimal("0.17"), new BigDecimal("0.13")
, new BigDecimal("0.11"), new BigDecimal("0.06"), new BigDecimal("0.05"), new BigDecimal("0.03")};
protected FormulaContext formulaContext;
private static Logger LOGGER = LoggerFactory.getLogger(FunctionBase.class);
final FormulaAgent agent;
public FunctionBase(FormulaContext formulaContext) {
......@@ -178,4 +182,35 @@ public class FunctionBase {
periodFormulaBlock.setUpdateTime(creatime);
SpringContextUtil.periodFormulaBlockMapper.insertSelective(periodFormulaBlock);
}
public static BigDecimal getCellValue(OperationEvaluationContext ec, FormulaContext formulaContext, FormulaAgent agent,
int rowIndex, int columnIndex, Long cellTemplateId) throws NoSuchFieldException, IllegalAccessException {
Field evaluatorField = OperationEvaluationContext.class.getDeclaredField("_bookEvaluator");
evaluatorField.setAccessible(true);
WorkbookEvaluator evaluator = (WorkbookEvaluator) evaluatorField.get(ec);
ValueEval eval = evaluator.evaluate(ec.getWorkbook().getSheet(ec.getSheetIndex()).getCell(rowIndex, columnIndex));
List<PeriodDataSource> dss = agent.queryManualDataSource(cellTemplateId, formulaContext.getProjectId(), formulaContext.getPeriod());
if (eval instanceof ErrorEval || eval == null || eval instanceof BlankEval) {
LOGGER.warn("[Formula_Exception] error eval for cell {} and error code {} and error String {}", cellTemplateId,
((ErrorEval) eval).getErrorCode(), ((ErrorEval) eval).getErrorString());
if (!dss.isEmpty()) return dss.get(0).getAmount();
} else {
String evalStr = OperandResolver.coerceValueToString(eval);
LOGGER.debug("[Formula_debug] eval other cell value {}", evalStr);
try {
if (!dss.isEmpty()) {
return new BigDecimal(evalStr).add(dss.get(0).getAmount());
}
} catch (Exception e) {
if (!dss.isEmpty())
return dss.get(0).getAmount();
e.printStackTrace();
}
}
return new BigDecimal(0);
}
}
......@@ -7,11 +7,14 @@ import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pwc.taxtech.atms.common.util.MyAsserts;
import pwc.taxtech.atms.constant.DataSourceName;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceType;
import pwc.taxtech.atms.dpo.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto;
import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.vat.entity.PeriodDataSource;
import pwc.taxtech.atms.vat.service.impl.FormulaAgent;
import java.lang.reflect.Field;
import java.math.BigDecimal;
......@@ -62,55 +65,38 @@ public class PSUM extends FunctionBase implements FreeRefFunction {
List<Object> dataSource) throws NoSuchFieldException, IllegalAccessException {
BigDecimal bigDecimal = new BigDecimal(0);
for (PCell pCell : pCells) {
Field evaluatorField = OperationEvaluationContext.class.getDeclaredField("_bookEvaluator");
evaluatorField.setAccessible(true);
WorkbookEvaluator evaluator = (WorkbookEvaluator) evaluatorField.get(ec);
ValueEval eval = evaluator.evaluate(ec.getWorkbook().getSheet(ec.getSheetIndex())
.getCell(pCell.rowIndex - 1, pCell.columnIndex - 1));
try {
List<CellTemplatePerGroupDto> cellTemplateDataList = agent.getCellTemplateGroupDto(formulaContext.getReportTemplateGroupId(),
formulaContext.getProjectId(), ec.getWorkbook().getSheetName(ec.getSheetIndex()), pCell.rowIndex-1,
pCell.columnIndex-1, formulaContext.getPeriod());
formulaContext.getProjectId(), ec.getWorkbook().getSheetName(ec.getSheetIndex()), pCell.rowIndex - 1,
pCell.columnIndex - 1, formulaContext.getPeriod());
MyAsserts.assertNotEmpty(cellTemplateDataList, Exceptions.PSUM_CELL_TEMP_NULL);
CellTemplatePerGroupDto cellTemplateData = cellTemplateDataList.get(0);
List<PeriodDataSource> dss = agent.queryManualDataSource(Long.parseLong(cellTemplateData.getCellTemplateId()),
formulaContext.getProjectId(), formulaContext.getPeriod());
BigDecimal cellValue = new BigDecimal(0);
if (eval instanceof ErrorEval || eval == null || eval instanceof BlankEval) {
LOGGER.warn("[PSUM_Exception] error eval for pcell {} and error code {} and error String {}", pCell.toString(),
((ErrorEval) eval).getErrorCode(), ((ErrorEval) eval).getErrorString());
if (!dss.isEmpty()) cellValue=dss.get(0).getAmount();
} else {
String evalStr = OperandResolver.coerceValueToString(eval);
logger.debug("[PSUM_debug] eval other cell value {}", evalStr);
try {
cellValue = new BigDecimal(evalStr).setScale(4,
BigDecimal.ROUND_HALF_DOWN);
if (!dss.isEmpty())
cellValue = cellValue.add(dss.get(0).getAmount());
} catch (Exception e) {
if (!dss.isEmpty())
cellValue = dss.get(0).getAmount();
else throw e;
}
}
BigDecimal cellValue = getCellValue(ec, formulaContext, agent, pCell.rowIndex - 1, pCell.columnIndex - 1,
Long.parseLong(cellTemplateData.getCellTemplateId()));
ReportCellDataSourceDto dto = new ReportCellDataSourceDto();
dto.fixedWithGroup(cellTemplateData );
dto.fixedWithGroup(cellTemplateData);
dto.setAmount(cellValue);
dto.setPeriod(formulaContext.getPeriod());
dto.setProjectId(formulaContext.getProjectId());
dto.setReportName(cellTemplateData.getReportCode());
dto.setRowIndex(pCell.rowIndex-1);
dto.setColumnIndex(pCell.columnIndex-1);
dto.setColumnName((pCell.columnIndex-1)+"列");
dto.setRowName((pCell.rowIndex-1)+"行");
dto.setReportName(DataSourceName.ReportDataSource);
dto.setType( FormulaDataSourceType.Report.getCode());
dataSource.add(dto);
bigDecimal=bigDecimal.add(cellValue);
bigDecimal = bigDecimal.add(cellValue);
}catch (Exception e){
e.printStackTrace();
}
}
return bigDecimal;
return bigDecimal.setScale(4, BigDecimal.ROUND_HALF_DOWN);
}
public static class PCell {
int rowIndex;
int columnIndex;
......
......@@ -38,4 +38,4 @@ api.url=http://etms.longi-silicon.com:8182
# Longi config
longi_api_basic_user=
longi_api_basic_pwd=
longi_api_gl_balance=http://39.105.197.175:13000/ETMSSB/Erp/GLBalance/ProxyServices/ErpQueryGLBalanceSoapProxy?wsdl
longi_api_gl_balance=http://39.105.197.175:13001/ETMSSB/Erp/GLBalance/ProxyServices/ErpQueryGLBalanceSoapProxy?wsdl
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