Commit 5fcd053f authored by eddie.woo's avatar eddie.woo

Merge branch 'dev_oracle' of http://code.tech.tax.asia.pwcinternal.com/root/atms into dev_oracle

parents d7cf6491 b3991e25
...@@ -94,7 +94,7 @@ public class InputInvoiceImportController { ...@@ -94,7 +94,7 @@ public class InputInvoiceImportController {
} }
} }
private int getDownloadFilePath(InputInvoicePreviewQueryParam paras, OutputStream outputStream, String projectId) { private int getDownloadFilePath(InputInvoicePreviewQueryParam paras, OutputStream outputStream, String projectId) {
List<InputInvoice> list = inputInvoiceDataImportService.getInputInvoiceTreeViewData(paras, projectId).getList(); List<InputInvoice> list = inputInvoiceDataImportService.getInputInvoiceTree(paras, projectId);
if (list.size() == 0) { if (list.size() == 0) {
return 0; return 0;
} }
...@@ -107,9 +107,9 @@ public class InputInvoiceImportController { ...@@ -107,9 +107,9 @@ public class InputInvoiceImportController {
inputInvoiceExportDto.setInvoiceDate(inputInvoice.getKPRQ()); inputInvoiceExportDto.setInvoiceDate(inputInvoice.getKPRQ());
inputInvoiceExportDto.setInvoiceNumber(inputInvoice.getFPHM()); inputInvoiceExportDto.setInvoiceNumber(inputInvoice.getFPHM());
inputInvoiceExportDto.setInvoiceTypeName(getFplx(inputInvoice.getFPLX())); inputInvoiceExportDto.setInvoiceTypeName(getFplx(inputInvoice.getFPLX()));
inputInvoiceExportDto.setPeriodId(Integer.parseInt(inputInvoice.getRZSJ().substring(5, 7))); inputInvoiceExportDto.setPeriodId(Integer.parseInt(inputInvoice.getRZSQ().substring(4, 6)));
inputInvoiceExportDto.setSellerTaxNumber(inputInvoice.getXFSH()); inputInvoiceExportDto.setSellerTaxNumber(inputInvoice.getXFSH());
inputInvoiceExportDto.setTaxAmount(inputInvoice.getHJSE() != null ? new BigDecimal(inputInvoice.getHJJE().replace(",","")) : BigDecimal.ZERO); inputInvoiceExportDto.setTaxAmount(inputInvoice.getHJSE() != null ? new BigDecimal(inputInvoice.getHJSE().replace(",","")) : BigDecimal.ZERO);
inputInvoiceExportDtos.add(inputInvoiceExportDto); inputInvoiceExportDtos.add(inputInvoiceExportDto);
} }
Map<String, String> header = new LinkedHashMap<>(); Map<String, String> header = new LinkedHashMap<>();
......
...@@ -112,20 +112,20 @@ public class OutputInvoiceController { ...@@ -112,20 +112,20 @@ public class OutputInvoiceController {
header.put("InvoiceNumber", "发票号码"); header.put("InvoiceNumber", "发票号码");
header.put("BuyerName", "购方企业名称"); header.put("BuyerName", "购方企业名称");
header.put("BuyerTaxNumber", "购方税号"); header.put("BuyerTaxNumber", "购方税号");
header.put("BankAccount", "银行账号"); // header.put("BankAccount", "银行账号");
header.put("PhoneNum", "地址电话"); // header.put("PhoneNum", "地址电话");
header.put("InvoiceDate", "开票日期"); header.put("InvoiceDate", "开票日期");
header.put("CodeVersion", "商品编码版本号"); // header.put("CodeVersion", "商品编码版本号");
header.put("DocumentNum", "单据号"); // header.put("DocumentNum", "单据号");
header.put("ProductName", "商品名称"); // header.put("ProductName", "商品名称");
header.put("ProductStandar", "规格"); // header.put("ProductStandar", "规格");
header.put("Unit", "单位"); // header.put("Unit", "单位");
header.put("Quantity", "数量"); // header.put("Quantity", "数量");
header.put("UnitPrice", "单价"); // header.put("UnitPrice", "单价");
header.put("Amount", "金额"); header.put("Amount", "金额");
header.put("TaxRate", "税率"); // header.put("TaxRate", "税率");
header.put("TaxAmount", "税额"); header.put("TaxAmount", "税额");
header.put("TaxClassCode", "税收分类编码"); // header.put("TaxClassCode", "税收分类编码");
ExcelUtil.exportExcel(header, list2, outputStream); ExcelUtil.exportExcel(header, list2, outputStream);
return list.size(); return list.size();
......
...@@ -22,33 +22,32 @@ public class OutputVATInvoiceInfoDto { ...@@ -22,33 +22,32 @@ public class OutputVATInvoiceInfoDto {
private String buyerName; private String buyerName;
@ExcelCell(index=5) @ExcelCell(index=5)
private String buyerTaxNumber; private String buyerTaxNumber;
@ExcelCell(index=6) // @ExcelCell(index=6)
private String bankAccount; private String bankAccount;
@ExcelCell(index=7) // @ExcelCell(index=7)
private String phoneNum; private String phoneNum;
@ExcelCell(index=8) @ExcelCell(index=6)
private Date invoiceDate; private Date invoiceDate;
@ExcelCell(index=9) // @ExcelCell(index=9)
private String codeVersion; private String codeVersion;
@ExcelCell(index=11) // @ExcelCell(index=11)
private String productName; private String productName;
@ExcelCell(index=10) // @ExcelCell(index=10)
private String documentNum; private String documentNum;
@ExcelCell(index=12) // @ExcelCell(index=12)
private String productStandard; private String productStandard;
@ExcelCell(index=13) // @ExcelCell(index=13)
private String unit; private String unit;
@ExcelCell(index=14) // @ExcelCell(index=14)
private Integer quantity; private Integer quantity;
@ExcelCell(index=15) // @ExcelCell(index=15)
private Double unitPrice; private Double unitPrice;
@ExcelCell(index=16) @ExcelCell(index=7)
private BigDecimal amount; private BigDecimal amount;
@ExcelCell(index=17) // @ExcelCell(index=17)
private BigDecimal taxRate; private BigDecimal taxRate;
@ExcelCell(index=18) @ExcelCell(index=8)
private BigDecimal taxAmount; private BigDecimal taxAmount;
@ExcelCell(index=19)
private String taxClassCode; private String taxClassCode;
@JsonProperty("periodID") @JsonProperty("periodID")
private int periodId; private int periodId;
......
...@@ -75,18 +75,18 @@ public class DataImportService extends BaseService { ...@@ -75,18 +75,18 @@ public class DataImportService extends BaseService {
//科目段 //科目段
GlBalanceExample.Criteria c = example.createCriteria().andSegment1EqualTo(organization.getClientCode()) GlBalanceExample.Criteria c = example.createCriteria().andSegment1EqualTo(organization.getClientCode())
.andPeriodNameEqualTo(dateFormat.format(calendar.getTime())); .andPeriodNameEqualTo(dateFormat.format(calendar.getTime()));
if(CollectionUtils.isNotEmpty(etCodeList)){ // if(CollectionUtils.isNotEmpty(etCodeList)){
c.andSegment3In(etCodeList); c.andSegment3In(etCodeList);
} // }
List<GlBalance> sg3List = glBalanceMapper.selectByExample(example); List<GlBalance> sg3List = glBalanceMapper.selectByExample(example);
GlBalanceExample example2 = new GlBalanceExample(); GlBalanceExample example2 = new GlBalanceExample();
//明细段 //明细段
GlBalanceExample.Criteria c2 = example2.createCriteria().andSegment1EqualTo(organization.getClientCode()) GlBalanceExample.Criteria c2 = example2.createCriteria().andSegment1EqualTo(organization.getClientCode())
.andPeriodNameEqualTo(dateFormat.format(calendar.getTime())); .andPeriodNameEqualTo(dateFormat.format(calendar.getTime()));
if(CollectionUtils.isNotEmpty(etCodeList)){ // if(CollectionUtils.isNotEmpty(etCodeList)){
c2.andSegment4In(etCodeList); c2.andSegment4In(etCodeList);
} // }
List<GlBalance> sg4List = glBalanceMapper.selectByExample(example2); List<GlBalance> sg4List = glBalanceMapper.selectByExample(example2);
for (StandardAccount standardAccount : stdAccountList) { for (StandardAccount standardAccount : stdAccountList) {
......
...@@ -55,7 +55,7 @@ public class InputInvoiceDataImportServiceImpl { ...@@ -55,7 +55,7 @@ public class InputInvoiceDataImportServiceImpl {
@Autowired @Autowired
private OrganizationMapper organizationMapper; private OrganizationMapper organizationMapper;
public PageInfo<InputInvoice> getInputInvoiceTreeViewData(InputInvoicePreviewQueryParam paras, String projectId) { public List<InputInvoice> getInputInvoiceTree(InputInvoicePreviewQueryParam paras, String projectId){
Project project = projectMapper.selectByPrimaryKey(projectId); Project project = projectMapper.selectByPrimaryKey(projectId);
Organization organization = organizationMapper.selectByPrimaryKey(project.getOrganizationId()); Organization organization = organizationMapper.selectByPrimaryKey(project.getOrganizationId());
InputInvoiceExample invoiceExample = new InputInvoiceExample(); InputInvoiceExample invoiceExample = new InputInvoiceExample();
...@@ -64,7 +64,7 @@ public class InputInvoiceDataImportServiceImpl { ...@@ -64,7 +64,7 @@ public class InputInvoiceDataImportServiceImpl {
paras.getPeriodEnd(), Constant.DateFormat.YYYYMM)).andRZJGEqualTo(INPUT_RZJG_SUCCESS).andRZZTEqualTo(INPUT_RZZT_OVER) paras.getPeriodEnd(), Constant.DateFormat.YYYYMM)).andRZJGEqualTo(INPUT_RZJG_SUCCESS).andRZZTEqualTo(INPUT_RZZT_OVER)
.andFPZTNotEqualTo("1"); .andFPZTNotEqualTo("1");
PageHelper.startPage(paras.getPageInfo().getPageIndex(), paras.getPageInfo().getPageSize());
List<InputInvoice> invoices = inputInvoiceMapper.selectByExample(invoiceExample); List<InputInvoice> invoices = inputInvoiceMapper.selectByExample(invoiceExample);
DecimalFormat df = new DecimalFormat("#,###.00"); DecimalFormat df = new DecimalFormat("#,###.00");
invoices.stream().forEach(x -> { invoices.stream().forEach(x -> {
...@@ -73,7 +73,12 @@ public class InputInvoiceDataImportServiceImpl { ...@@ -73,7 +73,12 @@ public class InputInvoiceDataImportServiceImpl {
x.setRZJG(convertRzjg(x.getRZJG())); x.setRZJG(convertRzjg(x.getRZJG()));
} }
); );
PageInfo<InputInvoice> pageInfo = new PageInfo<>(invoices); return invoices;
}
public PageInfo<InputInvoice> getInputInvoiceTreeViewData(InputInvoicePreviewQueryParam paras, String projectId) {
PageHelper.startPage(paras.getPageInfo().getPageIndex(), paras.getPageInfo().getPageSize());
PageInfo<InputInvoice> pageInfo = new PageInfo<>(getInputInvoiceTree(paras, projectId));
return pageInfo; return pageInfo;
} }
......
...@@ -147,7 +147,7 @@ public class ReportGeneratorImpl { ...@@ -147,7 +147,7 @@ public class ReportGeneratorImpl {
List<PeriodFormulaBlock> periodFormulaBlocks = periodFormulaBlockMapper.selectByExample(periodFormulaBlockExample2); List<PeriodFormulaBlock> periodFormulaBlocks = periodFormulaBlockMapper.selectByExample(periodFormulaBlockExample2);
//TODO:如果formula 为 ND(100) +ND(22) ,需要使用正则表达式拆分出自定义公式,然后根据自定义公式取formulablock 的数据进行替换 //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); Pattern p = Pattern.compile(regex);
String sourceFormula = StringUtils.isNotBlank(periodCellTemplateConfig.getKeyValueParsedFormula()) ? String sourceFormula = StringUtils.isNotBlank(periodCellTemplateConfig.getKeyValueParsedFormula()) ?
periodCellTemplateConfig.getKeyValueParsedFormula() : periodCellTemplateConfig.getKeyValueParsedFormula() :
...@@ -172,65 +172,12 @@ public class ReportGeneratorImpl { ...@@ -172,65 +172,12 @@ public class ReportGeneratorImpl {
//如果有正则匹配就进行更新公式解析 //如果有正则匹配就进行更新公式解析
if (isFind) { if (isFind) {
periodCellTemplateConfig.setParsedFormula(StringUtils.isNotBlank(resultFormula) ? resultFormula : null); 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); periodCellTemplateConfig.setFormula(StringUtils.isNotBlank(periodCellTemplateConfig.getFormula()) ? resultFormula : null);
periodCellTemplateConfigMapper.updateByPrimaryKeySelective(periodCellTemplateConfig); 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() Optional<PeriodCellTemplate> tempPeriodCellTemplate = resources.getPeriodCellTemplates().stream()
.filter(a -> a.getCellTemplateId().equals(periodCellTemplateConfig.getCellTemplateId())) .filter(a -> a.getCellTemplateId().equals(periodCellTemplateConfig.getCellTemplateId()))
.findFirst(); .findFirst();
......
...@@ -95,39 +95,8 @@ public class BB extends FunctionBase implements FreeRefFunction { ...@@ -95,39 +95,8 @@ public class BB extends FunctionBase implements FreeRefFunction {
return returnEval; return returnEval;
} else if (bo.getPeriod().intValue() == 0) { } else if (bo.getPeriod().intValue() == 0) {
Field evaluatorField = OperationEvaluationContext.class.getDeclaredField("_bookEvaluator"); cellValue = getCellValue(ec, formulaContext, agent, bo.getRowIndex() - 1, bo.getColumnIndex() - 1,
evaluatorField.setAccessible(true); Long.parseLong(cellTemplateData.getCellTemplateId()));
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;
}
}
nullCellDto.extractFromGroup(bo, formulaContext.getPeriod(), formulaContext.getYear(), cellTemplateData); nullCellDto.extractFromGroup(bo, formulaContext.getPeriod(), formulaContext.getYear(), cellTemplateData);
nullCellDto.setAmount(cellValue); nullCellDto.setAmount(cellValue);
......
package pwc.taxtech.atms.vat.service.impl.report.functions; package pwc.taxtech.atms.vat.service.impl.report.functions;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.ss.formula.OperationEvaluationContext; import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction; import org.apache.poi.ss.formula.functions.FreeRefFunction;
import pwc.taxtech.atms.common.util.DateUtils; import pwc.taxtech.atms.common.util.DateUtils;
import pwc.taxtech.atms.common.util.MyAsserts;
import pwc.taxtech.atms.common.util.SpringContextUtil; import pwc.taxtech.atms.common.util.SpringContextUtil;
import pwc.taxtech.atms.constant.Constant;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.dpo.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto;
import pwc.taxtech.atms.entity.AccountMapping; import pwc.taxtech.atms.entity.AccountMapping;
import pwc.taxtech.atms.entity.AccountMappingExample; import pwc.taxtech.atms.entity.AccountMappingExample;
import pwc.taxtech.atms.entity.EnterpriseAccountSetOrg; import pwc.taxtech.atms.entity.EnterpriseAccountSetOrg;
import pwc.taxtech.atms.entity.EnterpriseAccountSetOrgExample; import pwc.taxtech.atms.entity.EnterpriseAccountSetOrgExample;
import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.vat.entity.GlBalance; import pwc.taxtech.atms.vat.entity.GlBalance;
import pwc.taxtech.atms.vat.entity.GlBalanceExample; import pwc.taxtech.atms.vat.entity.GlBalanceExample;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -34,7 +43,7 @@ public class DFFS extends FunctionBase implements FreeRefFunction { ...@@ -34,7 +43,7 @@ public class DFFS extends FunctionBase implements FreeRefFunction {
int year = getIntParam(args[2], ec); int year = getIntParam(args[2], ec);
int period = getIntParam(args[3], ec); int period = getIntParam(args[3], ec);
String formulaExpression = "DFFS(" + type + "," + code + "," String formulaExpression = "DFFS(" + type + ",\"" + code + "\","
+ year + "," + period + ")"; + year + "," + period + ")";
logger.debug(formulaExpression); logger.debug(formulaExpression);
...@@ -46,7 +55,7 @@ public class DFFS extends FunctionBase implements FreeRefFunction { ...@@ -46,7 +55,7 @@ public class DFFS extends FunctionBase implements FreeRefFunction {
year = year + yearOffset; year = year + yearOffset;
Date date = DateUtils.strToDate(year + "-" + period + "-" + 15); Date date = DateUtils.strToDate(year + "-" + period + "-" + 15);
List<GlBalance> list; List<ReportCellDataSourceDto> dataSource = Lists.newArrayList();
if(type == 0){ if(type == 0){
EnterpriseAccountSetOrgExample example = new EnterpriseAccountSetOrgExample(); EnterpriseAccountSetOrgExample example = new EnterpriseAccountSetOrgExample();
example.createCriteria().andEffectiveDateLessThanOrEqualTo(date).andExpiredDateGreaterThanOrEqualTo(date).andOrganizationIdEqualTo(orgId); example.createCriteria().andEffectiveDateLessThanOrEqualTo(date).andExpiredDateGreaterThanOrEqualTo(date).andOrganizationIdEqualTo(orgId);
...@@ -58,18 +67,30 @@ public class DFFS extends FunctionBase implements FreeRefFunction { ...@@ -58,18 +67,30 @@ public class DFFS extends FunctionBase implements FreeRefFunction {
accountMappingExample.createCriteria().andOrganizationIdEqualTo(orgId).andEnterpriseAccountSetIdEqualTo(enterpriseAccountSetOrgs.get(0).getEnterpriseAccountSetId()); accountMappingExample.createCriteria().andOrganizationIdEqualTo(orgId).andEnterpriseAccountSetIdEqualTo(enterpriseAccountSetOrgs.get(0).getEnterpriseAccountSetId());
List<AccountMapping> accountMappings = SpringContextUtil.accountMappingMapper.selectByExample(accountMappingExample); List<AccountMapping> accountMappings = SpringContextUtil.accountMappingMapper.selectByExample(accountMappingExample);
double result = 0; double result = 0;
for(AccountMapping a : accountMappings){ for(AccountMapping a : accountMappings){
result += count(a.getEnterpriseAccountCode()); result += count(a.getEnterpriseAccountCode(), dataSource, period);
} }
Long dataSoureId = saveDataSource(ec, Collections.singletonList(dataSource),
FormulaDataSourceDetailType.FormulaDataSourceDto,
new BigDecimal(result), period, formulaContext.getReportTemplateGroupId(), formulaContext.getProjectId());
saveFormulaBlock(period, ec, formulaExpression, new BigDecimal(result), dataSoureId, formulaContext.getProjectId());
return new NumberEval(result); return new NumberEval(result);
} else if(type == 1){ } else if(type == 1){
return new NumberEval(count(code));
double result = count(code, dataSource, period);
Long dataSoureId = saveDataSource(ec, Collections.singletonList(dataSource),
FormulaDataSourceDetailType.FormulaDataSourceDto,
new BigDecimal(result), period, formulaContext.getReportTemplateGroupId(), formulaContext.getProjectId());
saveFormulaBlock(period, ec, formulaExpression, new BigDecimal(result), dataSoureId, formulaContext.getProjectId());
return new NumberEval(result);
} }
return NumberEval.ZERO; return NumberEval.ZERO;
} }
private double count(String code){ private double count(String code, List<ReportCellDataSourceDto> contain, int period){
GlBalanceExample glBalanceExample = new GlBalanceExample(); GlBalanceExample glBalanceExample = new GlBalanceExample();
GlBalanceExample.Criteria c1 = glBalanceExample.createCriteria().andSegment3EqualTo(code); GlBalanceExample.Criteria c1 = glBalanceExample.createCriteria().andSegment3EqualTo(code);
GlBalanceExample.Criteria c2 = glBalanceExample.createCriteria().andSegment4EqualTo(code); GlBalanceExample.Criteria c2 = glBalanceExample.createCriteria().andSegment4EqualTo(code);
...@@ -82,6 +103,15 @@ public class DFFS extends FunctionBase implements FreeRefFunction { ...@@ -82,6 +103,15 @@ public class DFFS extends FunctionBase implements FreeRefFunction {
if(CollectionUtils.isEmpty(temp)){ if(CollectionUtils.isEmpty(temp)){
temp = list; temp = list;
} }
for(GlBalance glBalance : temp){
ReportCellDataSourceDto dto = new ReportCellDataSourceDto();
dto.setAmount(glBalance.getPtdCr());
dto.setPeriod(period);
dto.setIsOnlyManualInput(Boolean.FALSE);
dto.setName(Constant.DataSourceName.ReportDataSource);
contain.add(dto);
}
return temp.stream().mapToDouble(a -> a.getPtdCr().doubleValue()).sum(); return temp.stream().mapToDouble(a -> a.getPtdCr().doubleValue()).sum();
} }
} }
...@@ -2,19 +2,22 @@ package pwc.taxtech.atms.vat.service.impl.report.functions; ...@@ -2,19 +2,22 @@ package pwc.taxtech.atms.vat.service.impl.report.functions;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import org.apache.poi.ss.formula.OperationEvaluationContext; import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.EvaluationException; import org.apache.poi.ss.formula.WorkbookEvaluator;
import org.apache.poi.ss.formula.eval.OperandResolver; import org.apache.poi.ss.formula.eval.*;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import pwc.taxtech.atms.common.util.MyAsserts;
import pwc.taxtech.atms.common.util.SpringContextUtil; import pwc.taxtech.atms.common.util.SpringContextUtil;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType; import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceType; 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.PeriodDataSource;
import pwc.taxtech.atms.vat.entity.PeriodDataSourceDetail; import pwc.taxtech.atms.vat.entity.PeriodDataSourceDetail;
import pwc.taxtech.atms.vat.entity.PeriodFormulaBlock; import pwc.taxtech.atms.vat.entity.PeriodFormulaBlock;
import pwc.taxtech.atms.vat.service.impl.FormulaAgent; import pwc.taxtech.atms.vat.service.impl.FormulaAgent;
import java.lang.reflect.Field;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
...@@ -27,6 +30,7 @@ public class FunctionBase { ...@@ -27,6 +30,7 @@ public class FunctionBase {
public static final BigDecimal[] defaultTaxRates = {new BigDecimal("0.17"), new BigDecimal("0.13") 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")}; , new BigDecimal("0.11"), new BigDecimal("0.06"), new BigDecimal("0.05"), new BigDecimal("0.03")};
protected FormulaContext formulaContext; protected FormulaContext formulaContext;
private static Logger LOGGER = LoggerFactory.getLogger(FunctionBase.class);
final FormulaAgent agent; final FormulaAgent agent;
public FunctionBase(FormulaContext formulaContext) { public FunctionBase(FormulaContext formulaContext) {
...@@ -178,4 +182,35 @@ public class FunctionBase { ...@@ -178,4 +182,35 @@ public class FunctionBase {
periodFormulaBlock.setUpdateTime(creatime); periodFormulaBlock.setUpdateTime(creatime);
SpringContextUtil.periodFormulaBlockMapper.insertSelective(periodFormulaBlock); 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);
}
} }
...@@ -14,6 +14,8 @@ import pwc.taxtech.atms.dto.vatdto.InputInvoiceDataSourceDto; ...@@ -14,6 +14,8 @@ import pwc.taxtech.atms.dto.vatdto.InputInvoiceDataSourceDto;
import pwc.taxtech.atms.vat.entity.InputInvoice; import pwc.taxtech.atms.vat.entity.InputInvoice;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
...@@ -127,8 +129,8 @@ public class JXFP extends FunctionBase implements FreeRefFunction { ...@@ -127,8 +129,8 @@ public class JXFP extends FunctionBase implements FreeRefFunction {
Date finalEndDate1 = endDate; Date finalEndDate1 = endDate;
Date finalStartDate = startDate; Date finalStartDate = startDate;
inputInvoices = inputInvoices.stream() inputInvoices = inputInvoices.stream()
.filter(a -> DateUtils.strToDate(a.getRZSJ()).after(finalStartDate) .filter(a -> strToDate(a.getRZSQ()).after(finalStartDate)
&& DateUtils.strToDate(a.getRZSJ()).before(finalEndDate1)) && strToDate(a.getRZSQ()).before(finalEndDate1))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }
...@@ -188,4 +190,12 @@ public class JXFP extends FunctionBase implements FreeRefFunction { ...@@ -188,4 +190,12 @@ public class JXFP extends FunctionBase implements FreeRefFunction {
formulaContext.getProjectId()); formulaContext.getProjectId());
return NumberEval.ZERO; return NumberEval.ZERO;
} }
private static Date strToDate(String strDate) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMM");
ParsePosition pos = new ParsePosition(0);
Date strtodate = formatter.parse(strDate, pos);
return strtodate;
}
} }
...@@ -7,11 +7,14 @@ import org.apache.poi.ss.formula.functions.FreeRefFunction; ...@@ -7,11 +7,14 @@ import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import pwc.taxtech.atms.common.util.MyAsserts; 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.FormulaDataSourceDetailType;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceType;
import pwc.taxtech.atms.dpo.CellTemplatePerGroupDto; import pwc.taxtech.atms.dpo.CellTemplatePerGroupDto;
import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto; import pwc.taxtech.atms.dto.vatdto.ReportCellDataSourceDto;
import pwc.taxtech.atms.exception.Exceptions; import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.vat.entity.PeriodDataSource; import pwc.taxtech.atms.vat.entity.PeriodDataSource;
import pwc.taxtech.atms.vat.service.impl.FormulaAgent;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -62,54 +65,38 @@ public class PSUM extends FunctionBase implements FreeRefFunction { ...@@ -62,54 +65,38 @@ public class PSUM extends FunctionBase implements FreeRefFunction {
List<Object> dataSource) throws NoSuchFieldException, IllegalAccessException { List<Object> dataSource) throws NoSuchFieldException, IllegalAccessException {
BigDecimal bigDecimal = new BigDecimal(0); BigDecimal bigDecimal = new BigDecimal(0);
for (PCell pCell : pCells) { for (PCell pCell : pCells) {
Field evaluatorField = OperationEvaluationContext.class.getDeclaredField("_bookEvaluator"); try {
evaluatorField.setAccessible(true); List<CellTemplatePerGroupDto> cellTemplateDataList = agent.getCellTemplateGroupDto(formulaContext.getReportTemplateGroupId(),
WorkbookEvaluator evaluator = (WorkbookEvaluator) evaluatorField.get(ec); formulaContext.getProjectId(), ec.getWorkbook().getSheetName(ec.getSheetIndex()), pCell.rowIndex - 1,
ValueEval eval = evaluator.evaluate(ec.getWorkbook().getSheet(ec.getSheetIndex()) pCell.columnIndex - 1, formulaContext.getPeriod());
.getCell(pCell.rowIndex - 1, pCell.columnIndex - 1)); MyAsserts.assertNotEmpty(cellTemplateDataList, Exceptions.PSUM_CELL_TEMP_NULL);
CellTemplatePerGroupDto cellTemplateData = cellTemplateDataList.get(0);
List<CellTemplatePerGroupDto> cellTemplateDataList = agent.getCellTemplateGroupDto(formulaContext.getReportTemplateGroupId(),
formulaContext.getProjectId(), ec.getWorkbook().getSheetName(ec.getSheetIndex()), pCell.rowIndex - 1, BigDecimal cellValue = getCellValue(ec, formulaContext, agent, pCell.rowIndex - 1, pCell.columnIndex - 1,
pCell.columnIndex - 1, formulaContext.getPeriod()); Long.parseLong(cellTemplateData.getCellTemplateId()));
ReportCellDataSourceDto dto = new ReportCellDataSourceDto();
MyAsserts.assertNotEmpty(cellTemplateDataList, Exceptions.PSUM_CELL_TEMP_NULL); dto.fixedWithGroup(cellTemplateData);
CellTemplatePerGroupDto cellTemplateData = cellTemplateDataList.get(0); dto.setAmount(cellValue);
dto.setPeriod(formulaContext.getPeriod());
List<PeriodDataSource> dss = agent.queryManualDataSource(Long.parseLong(cellTemplateData.getCellTemplateId()), dto.setProjectId(formulaContext.getProjectId());
formulaContext.getProjectId(), formulaContext.getPeriod()); dto.setRowIndex(pCell.rowIndex-1);
BigDecimal cellValue = new BigDecimal(0); dto.setColumnIndex(pCell.columnIndex-1);
if (eval instanceof ErrorEval || eval == null || eval instanceof BlankEval) { dto.setColumnName((pCell.columnIndex-1)+"列");
LOGGER.warn("[PSUM_Exception] error eval for pcell {} and error code {} and error String {}", pCell.toString(), dto.setRowName((pCell.rowIndex-1)+"行");
((ErrorEval) eval).getErrorCode(), ((ErrorEval) eval).getErrorString()); dto.setReportName(DataSourceName.ReportDataSource);
if (!dss.isEmpty()) cellValue = dss.get(0).getAmount(); dto.setType( FormulaDataSourceType.Report.getCode());
} else {
String evalStr = OperandResolver.coerceValueToString(eval); dataSource.add(dto);
logger.debug("[PSUM_debug] eval other cell value {}", evalStr); bigDecimal = bigDecimal.add(cellValue);
try { }catch (Exception e){
cellValue = new BigDecimal(evalStr); e.printStackTrace();
if (!dss.isEmpty())
cellValue = cellValue.add(dss.get(0).getAmount());
} catch (Exception e) {
if (!dss.isEmpty())
cellValue = dss.get(0).getAmount();
e.printStackTrace();
}
} }
ReportCellDataSourceDto dto = new ReportCellDataSourceDto();
dto.fixedWithGroup(cellTemplateData);
dto.setAmount(cellValue);
dto.setPeriod(formulaContext.getPeriod());
dto.setProjectId(formulaContext.getProjectId());
dto.setReportName(cellTemplateData.getReportCode());
dataSource.add(dto);
bigDecimal = bigDecimal.add(cellValue);
} }
return bigDecimal.setScale(4, BigDecimal.ROUND_HALF_DOWN); return bigDecimal.setScale(4, BigDecimal.ROUND_HALF_DOWN);
} }
public static class PCell { public static class PCell {
int rowIndex; int rowIndex;
int columnIndex; int columnIndex;
......
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