Commit f69410c1 authored by frank.xa.zhang's avatar frank.xa.zhang

fixed report generate issue

parent f89308cd
......@@ -5,6 +5,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import pwc.taxtech.atms.dao.FormulaAdminMapper;
import pwc.taxtech.atms.dao.OrganizationMapper;
import pwc.taxtech.atms.dao.ProjectMapper;
import pwc.taxtech.atms.dao.ProjectServiceTypeMapper;
import pwc.taxtech.atms.dao.dao.ProjectDao;
......@@ -44,6 +45,7 @@ public class SpringContextUtil implements ApplicationContextAware {
public static AssetsListMapper assetsListMapper;
public static ProjectMapper projectMapper;
public static CellDataSourceMapper cellDataSourceMapper;
public static OrganizationMapper organizationMapper;
/**
* 获取bean
......@@ -84,5 +86,6 @@ public class SpringContextUtil implements ApplicationContextAware {
assetsListMapper = webApplicationContext.getBean(AssetsListMapper.class);
projectMapper = webApplicationContext.getBean(ProjectMapper.class);
cellDataSourceMapper = webApplicationContext.getBean(CellDataSourceMapper.class);
organizationMapper = webApplicationContext.getBean(OrganizationMapper.class);
}
}
package pwc.taxtech.atms.constant;
import java.io.File;
import java.util.Locale;
import java.util.UUID;
public final class Constant {
......@@ -42,6 +43,7 @@ public final class Constant {
public static final String IMAGE_FORMART_ = "png";
public static final String EMPTY = "";
public static final String DateTimeFormate = "{0}年{1}月";
public static class DataSourceName {
public static final String KeyValueDataSource = "KeyValueDataSource";
......@@ -69,4 +71,10 @@ public final class Constant {
public static String ScanPass = "扫描认证";
public static String NotPass = "未认证";
}
public static class ReportBuildInStringFormat {
public static final String TimeInterval = "税款所属时间: 自{0}年{1}月{2}日至{0}年{1}月{3}日";
public static final String FillForm = "填表日期: {0}年{1}月{2}日";
public static final String TaxPayer = "纳税人名称: {0}";
}
}
\ No newline at end of file
......@@ -26,7 +26,10 @@ public class ReportController {
@RequestMapping(value = "updateConfig/{projectId}/{ifDeleteManualDataSource}/{period}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public OperationResultDto updateConfig(@PathVariable String projectId, @PathVariable Boolean ifDeleteManualDataSource, @PathVariable Integer period, @RequestParam String generator) {
return reportService.updateConfig(projectId, period, ifDeleteManualDataSource, generator);
// return reportService.updateConfig(projectId, period, ifDeleteManualDataSource, generator);
OperationResultDto operationResultDto = new OperationResultDto();
operationResultDto.setResult(true);
return operationResultDto;
}
@RequestMapping(value = "generateByTotal/{projectId}/{ifDeleteManualDataSource}/{period}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
......
......@@ -113,5 +113,5 @@ public interface InputVATInvoiceMapper extends MyVatMapper {
List<InputVATInvoice> getInputVATInvoiceCountByConditionWithPaging(@Param("paras") InputInvoicePreviewQueryParam param,@Param("limitFrom") int limitFrom);
List<InputVATInvoiceResultDto> getInputVATInvoiceResultDto(String dbName);
List<InputVATInvoiceResultDto> getInputVATInvoiceResultDto(@Param("dbName")String dbName);
}
\ No newline at end of file
......@@ -183,5 +183,5 @@ public interface OutputVATInvoiceMapper extends MyVatMapper {
" ")
List<OutputVATInvoiceInfoDto> queryOutputDetailWithItem(Integer period);
List<OutputVATInvoiceDto> getVatInvoiceWithItems(String dbName);
List<OutputVATInvoiceDto> getVatInvoiceWithItems(@Param("dbName")String dbName);
}
\ No newline at end of file
......@@ -86,6 +86,9 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
formulaContext.setReportTemplateGroupID(templateGroupID);
formulaContext.setProjectID(project.getID());
formulaContext.setYear(project.getYear());
formulaContext.setIsYear(period == 0);
formulaContext.setIfRound(true);
formulaContext.setOrganizationID(project.getOrganizationID());
formulaContext.setIfRound(true);
......@@ -135,9 +138,13 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
//todo:后面单独处理kv的公式
if (StringUtils.isNotBlank(v.getFormula()) && !v.getFormula().contains("@")) {
cell.setCellFormula(v.getFormula());
logger.debug("formula:" + v.getFormula());
//kv 公式处理
} else if (v.getFormula().startsWith("@")) {
cell.setCellFormula(v.getKeyValueParsedFormula());
if (StringUtils.isNotBlank(v.getKeyValueParsedFormula())) {
cell.setCellFormula(v.getKeyValueParsedFormula());
logger.debug("formula:" + v.getKeyValueParsedFormula());
}
}
});
}
......@@ -343,7 +350,6 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
}
}
}
} else {
return "GenerateReport failed";
}
......@@ -416,9 +422,10 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
* @param workbook 工作簿
*/
private void addFunctionsToWorkbook(Workbook workbook, FormulaContext formulaContext) {
String[] functionNames = {"SGSR", "FSJZ", "ND", "BB", "XXFP", "GZSD"};
String[] functionNames = {"SGSR", "FSJZ", "ND", "BB", "XXFP", "GZSD", "ProjectContext", "JXFPMX"};
FreeRefFunction[] functionImpls = {new SGSR(formulaContext), new FSJZ(formulaContext), new ND(formulaContext),
new BB(formulaContext), new XXFP(formulaContext), new GZSD(formulaContext)};
new BB(formulaContext), new XXFP(formulaContext), new GZSD(formulaContext), new ProjectContext(formulaContext)
, new JXFPMX(formulaContext)};
UDFFinder udfs = new DefaultUDFFinder(functionNames, functionImpls);
UDFFinder udfToolpack = new AggregatingUDFFinder(udfs);
workbook.addToolPack(udfToolpack);
......
......@@ -2,6 +2,7 @@ package pwc.taxtech.atms.vat.service.impl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.common.datasource.ShardingContextHolder;
import pwc.taxtech.atms.constant.enums.*;
import pwc.taxtech.atms.dto.OperationResultDto;
......@@ -131,22 +132,23 @@ public class ReportServiceImpl extends VatAbstractService implements ReportServi
List<PeriodTemplate> periodTemplateList = new ArrayList<>();
for (Template template : templates) {
PeriodTemplate periodTemplate = new PeriodTemplate();
CommonUtils.copyProperties(template, periodTemplate);
periodTemplate.setId(distributedIDService.nextId());
periodTemplate.setPeriod(period);
periodTemplate.setName(template.getName());
periodTemplate.setCode(template.getCode());
periodTemplate.setPath(template.getPath());
periodTemplate.setReportType(template.getReportType());
periodTemplate.setTemplateGroupId(template.getTemplateGroupId());
periodTemplate.setOrderIndex(template.getOrderIndex());
periodTemplate.setCreateTime(template.getCreateTime());
periodTemplate.setUpdateTime(template.getUpdateTime());
periodTemplate.setIsSystemType(template.getIsSystemType());
periodTemplate.setIsActiveAssociation(template.getIsActiveAssociation());
periodTemplate.setParentId(template.getParentId());
// periodTemplate.setName(template.getName());
// periodTemplate.setCode(template.getCode());
// periodTemplate.setPath(template.getPath());
// periodTemplate.setReportType(template.getReportType());
// periodTemplate.setTemplateGroupId(template.getTemplateGroupId());
// periodTemplate.setOrderIndex(template.getOrderIndex());
// periodTemplate.setCreateTime(template.getCreateTime());
// periodTemplate.setUpdateTime(template.getUpdateTime());
// periodTemplate.setIsSystemType(template.getIsSystemType());
// periodTemplate.setIsActiveAssociation(template.getIsActiveAssociation());
// periodTemplate.setParentId(template.getParentId());
periodTemplate.setTemplateId(template.getId());
periodTemplate.setCreateBy(template.getCreateBy());
periodTemplate.setUpdateBy(template.getUpdateBy());
// periodTemplate.setCreateBy(template.getCreateBy());
// periodTemplate.setUpdateBy(template.getUpdateBy());
periodTemplateList.add(periodTemplate);
}
......@@ -157,22 +159,23 @@ public class ReportServiceImpl extends VatAbstractService implements ReportServi
List<PeriodCellTemplate> periodCellTemplateList = new ArrayList<>();
for (CellTemplate cellTemplate : cellTemplateList) {
PeriodCellTemplate periodCellTemplate = new PeriodCellTemplate();
CommonUtils.copyProperties(cellTemplate, periodCellTemplate);
periodCellTemplate.setId(distributedIDService.nextId());
periodCellTemplate.setPeriod(period);
periodCellTemplate.setReportTemplateId(cellTemplate.getReportTemplateId());
periodCellTemplate.setRowIndex(cellTemplate.getRowIndex());
periodCellTemplate.setRowName(cellTemplate.getRowName());
periodCellTemplate.setColumnIndex(cellTemplate.getColumnIndex());
periodCellTemplate.setColumnName(cellTemplate.getColumnName());
periodCellTemplate.setComment(cellTemplate.getComment());
periodCellTemplate.setCreateTime(cellTemplate.getCreateTime());
periodCellTemplate.setUpdateTime(cellTemplate.getUpdateTime());
// periodCellTemplate.setReportTemplateId(cellTemplate.getReportTemplateId());
// periodCellTemplate.setRowIndex(cellTemplate.getRowIndex());
// periodCellTemplate.setRowName(cellTemplate.getRowName());
// periodCellTemplate.setColumnIndex(cellTemplate.getColumnIndex());
// periodCellTemplate.setColumnName(cellTemplate.getColumnName());
// periodCellTemplate.setComment(cellTemplate.getComment());
// periodCellTemplate.setCreateTime(cellTemplate.getCreateTime());
// periodCellTemplate.setUpdateTime(cellTemplate.getUpdateTime());
periodCellTemplate.setCellTemplateId(cellTemplate.getId());
periodCellTemplate.setDataType(cellTemplate.getDataType());
periodCellTemplate.setIsReadOnly(cellTemplate.getIsReadOnly());
periodCellTemplate.setCopyFromId(cellTemplate.getCopyFromId());
periodCellTemplate.setCreateBy(cellTemplate.getCreateBy());
periodCellTemplate.setUpdateBy(cellTemplate.getUpdateBy());
// periodCellTemplate.setDataType(cellTemplate.getDataType());
// periodCellTemplate.setIsReadOnly(cellTemplate.getIsReadOnly());
// periodCellTemplate.setCopyFromId(cellTemplate.getCopyFromId());
// periodCellTemplate.setCreateBy(cellTemplate.getCreateBy());
// periodCellTemplate.setUpdateBy(cellTemplate.getUpdateBy());
periodCellTemplateList.add(periodCellTemplate);
}
......@@ -183,29 +186,30 @@ public class ReportServiceImpl extends VatAbstractService implements ReportServi
List<PeriodCellTemplateConfig> periodCellTemplateConfigList = new ArrayList<>();
for (CellTemplateConfig cellTemplateConfig : cellTemplateConfigList) {
PeriodCellTemplateConfig periodCellTemplateConfig = new PeriodCellTemplateConfig();
CommonUtils.copyProperties(cellTemplateConfig, periodCellTemplateConfig);
periodCellTemplateConfig.setId(distributedIDService.nextId());
periodCellTemplateConfig.setPeriod(period);
periodCellTemplateConfig.setCellTemplateId(cellTemplateConfig.getCellTemplateId());
periodCellTemplateConfig.setReportTemplateId(cellTemplateConfig.getReportTemplateId());
periodCellTemplateConfig.setDataSourceType(cellTemplateConfig.getDataSourceType());
periodCellTemplateConfig.setFormula(cellTemplateConfig.getFormula());
// periodCellTemplateConfig.setCellTemplateId(cellTemplateConfig.getCellTemplateId());
// periodCellTemplateConfig.setReportTemplateId(cellTemplateConfig.getReportTemplateId());
// periodCellTemplateConfig.setDataSourceType(cellTemplateConfig.getDataSourceType());
// periodCellTemplateConfig.setFormula(cellTemplateConfig.getFormula());
periodCellTemplateConfig.setParsedFormula(StringUtils.EMPTY);
periodCellTemplateConfig.setFormulaDescription(cellTemplateConfig.getFormulaDescription());
periodCellTemplateConfig.setAccountCodes(cellTemplateConfig.getAccountCodes());
periodCellTemplateConfig.setInvoiceType(cellTemplateConfig.getInvoiceType());
periodCellTemplateConfig.setTaxRate(cellTemplateConfig.getTaxRate());
periodCellTemplateConfig.setInvoiceAmountType(cellTemplateConfig.getInvoiceAmountType());
periodCellTemplateConfig.setModelIds(cellTemplateConfig.getModelIds());
periodCellTemplateConfig.setCreateBy(cellTemplateConfig.getCreateBy());
periodCellTemplateConfig.setCreateTime(cellTemplateConfig.getCreateTime());
periodCellTemplateConfig.setUpdateBy(cellTemplateConfig.getUpdateBy());
periodCellTemplateConfig.setUpdateTime(cellTemplateConfig.getUpdateTime());
periodCellTemplateConfig.setInvoiceCategory(cellTemplateConfig.getInvoiceCategory());
periodCellTemplateConfig.setFormulaDataSource(cellTemplateConfig.getFormulaDataSource());
periodCellTemplateConfig.setValidation(cellTemplateConfig.getValidation());
// periodCellTemplateConfig.setFormulaDescription(cellTemplateConfig.getFormulaDescription());
// periodCellTemplateConfig.setAccountCodes(cellTemplateConfig.getAccountCodes());
// periodCellTemplateConfig.setInvoiceType(cellTemplateConfig.getInvoiceType());
// periodCellTemplateConfig.setTaxRate(cellTemplateConfig.getTaxRate());
// periodCellTemplateConfig.setInvoiceAmountType(cellTemplateConfig.getInvoiceAmountType());
// periodCellTemplateConfig.setModelIds(cellTemplateConfig.getModelIds());
// periodCellTemplateConfig.setCreateBy(cellTemplateConfig.getCreateBy());
// periodCellTemplateConfig.setCreateTime(cellTemplateConfig.getCreateTime());
// periodCellTemplateConfig.setUpdateBy(cellTemplateConfig.getUpdateBy());
// periodCellTemplateConfig.setUpdateTime(cellTemplateConfig.getUpdateTime());
// periodCellTemplateConfig.setInvoiceCategory(cellTemplateConfig.getInvoiceCategory());
// periodCellTemplateConfig.setFormulaDataSource(cellTemplateConfig.getFormulaDataSource());
// periodCellTemplateConfig.setValidation(cellTemplateConfig.getValidation());
periodCellTemplateConfig.setParsedValidation(StringUtils.EMPTY);
periodCellTemplateConfig.setValidationDescription(cellTemplateConfig.getValidationDescription());
periodCellTemplateConfig.setVoucherKeyword(cellTemplateConfig.getVoucherKeyword());
// periodCellTemplateConfig.setValidationDescription(cellTemplateConfig.getValidationDescription());
// periodCellTemplateConfig.setVoucherKeyword(cellTemplateConfig.getVoucherKeyword());
periodCellTemplateConfig.setCellTemplateConfigId(cellTemplateConfig.getId());
if (cellTemplateConfig.getFormula().startsWith("@")) {
//todo: get the keyvalue from table add to keyvalue parsed formula
......
......@@ -61,9 +61,9 @@ public class FSJZ extends FunctionBase implements FreeRefFunction {
year = formulaContext.getYear();
}
int[] yearOffset = {};
Integer yearOffset = 0;
period = FormulaHelper.getPeriod(period, yearOffset, formulaContext);
year = year + yearOffset[0];
year = year + yearOffset;
if (accountType == 0) {
//标准账套
......
......@@ -53,14 +53,14 @@ public class FormulaHelper {
return columnStr;
}
public static int getPeriod(int parameterPeriod, int[] yearOffset, FormulaContext formulaFunctionContext) {
yearOffset[0] = 0;
public static int getPeriod(int parameterPeriod, Integer yearOffset, FormulaContext formulaFunctionContext) {
yearOffset = 0;
if (parameterPeriod == -99) {
return parameterPeriod;
} else if (parameterPeriod <= -1) {
int period = parameterPeriod + formulaFunctionContext.getPeriod();
while (period <= 0) {
yearOffset[0]--;
yearOffset--;
period += 12;
//throw new NotImplementedException();
}
......
......@@ -71,17 +71,15 @@ public class FunctionBase {
}
}
public int getPeriod(int parameterPeriod, int[] yearOffset) {
if (yearOffset.length == 0) {
yearOffset = new int[10];
}
yearOffset[0] = 0;
public int getPeriod(int parameterPeriod, Integer yearOffset) {
yearOffset = 0;
if (parameterPeriod == -99) {
return parameterPeriod;
} else if (parameterPeriod <= -1) {
int period = parameterPeriod + formulaContext.getPeriod();
while (period <= 0) {
yearOffset[0]--;
yearOffset--;
period += 12;
}
return period;
......
......@@ -54,15 +54,15 @@ public class JXFP extends FunctionBase implements FreeRefFunction {
+ authenticationType + "," + resultType + "," + period + ")";
logger.debug(formulaExpression);
int[] yearOffset = {};
Integer yearOffset = 0;
certificationPeriod = getPeriod(certificationPeriod, yearOffset);
if (yearOffset[0] < 0) {
if (yearOffset < 0) {
return NumberEval.ZERO;
}
period = getPeriod(period, yearOffset);
if (yearOffset[0] < 0) {
if (yearOffset < 0) {
return NumberEval.ZERO;
}
......
......@@ -48,9 +48,9 @@ public class JXFPMX extends FunctionBase implements FreeRefFunction {
logger.debug(formulaExpression);
int curYear = formulaContext.getYear();
int[] yearOffSet = {};
Integer yearOffSet = 0;
period = getPeriod(period, yearOffSet);
curYear = curYear + yearOffSet[0];
curYear = curYear + yearOffSet;
BigDecimal taxRateVal;
if (taxRate.equals(Constant.Other)) {
......
package pwc.taxtech.atms.vat.service.impl.report.functions;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.StringValueEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.joda.time.DateTime;
import org.thymeleaf.expression.Dates;
import pwc.taxtech.atms.common.util.SpringContextUtil;
import pwc.taxtech.atms.constant.Constant;
import pwc.taxtech.atms.entitiy.OrganizationExample;
import pwc.taxtech.atms.vat.entity.Report;
import java.util.Calendar;
import java.util.Date;
public class ProjectContext extends FunctionBase implements FreeRefFunction {
public ProjectContext(FormulaContext formulaContext) {
super(formulaContext);
}
@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
if (args.length < 2) {
return StringEval.EMPTY_INSTANCE;
}
String code = this.getStringParam(args[0], ec);
Integer parameterInt = this.getIntParam(args[1], ec);
Calendar calendar = Calendar.getInstance();
Calendar calendar2 = Calendar.getInstance();
switch (code) {
case "TaxPayer":
String taxPayerName =
SpringContextUtil.organizationMapper.selectByPrimaryKey(formulaContext.getOrganizationID()).getName();
if (StringUtils.isNotBlank(taxPayerName)) {
return new StringEval(String.format(Constant.ReportBuildInStringFormat.TaxPayer, taxPayerName));
} else {
return new StringEval(String.format(Constant.ReportBuildInStringFormat.TaxPayer, " "));
}
case "DataTime":
return new StringEval(String.format(Constant.DateTimeFormate, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)));
case "FilterDate":
return new StringEval(String.format(Constant.DateTimeFormate, formulaContext.getYear(), formulaContext.getPeriod()));
case "TimeInterval":
Date beginOfPeriod = new Date(formulaContext.getYear(), formulaContext.getIsYear() ? 1 : formulaContext.getPeriod(), 1);
calendar.setTime(beginOfPeriod);
calendar.add(Calendar.YEAR, 1);
calendar.add(Calendar.DAY_OF_MONTH, -1);
calendar2.setTime(beginOfPeriod);
calendar2.add(Calendar.MONTH, 1);
calendar2.add(Calendar.DAY_OF_MONTH, -1);
Date endOfPeriod = formulaContext.getIsYear() ? calendar.getTime() : calendar2.getTime();
calendar.setTime(beginOfPeriod);
calendar2.setTime(endOfPeriod);
return new StringEval(String.format(Constant.ReportBuildInStringFormat.TimeInterval, formulaContext.getYear()
, formulaContext.getPeriod(), calendar.get(Calendar.DAY_OF_MONTH), calendar2.get(Calendar.DAY_OF_MONTH)));
case "FillForm":
Report report = SpringContextUtil.reportMapper.selectByPrimaryKey(formulaContext.getReportID());
if (report != null) {
return new StringEval(String.format(Constant.ReportBuildInStringFormat.FillForm, report.getUpdateTime().getYear()
, report.getUpdateTime().getMonth(), report.getUpdateTime().getDay()));
} else {
return new StringEval(String.format(Constant.ReportBuildInStringFormat.FillForm, " ", " ", " "));
}
case "TaxPayerNo":
String taxPayerNo = SpringContextUtil.organizationMapper.selectByPrimaryKey(formulaContext.getOrganizationID()).getTaxPayerNumber();
if (StringUtils.isNotBlank(taxPayerNo) && taxPayerNo.length() - 1 >= parameterInt) {
return new StringEval(String.valueOf(taxPayerNo.charAt(parameterInt)));
}
break;
default:
break;
}
return StringEval.EMPTY_INSTANCE;
}
}
......@@ -62,9 +62,9 @@ public class SGSR implements FreeRefFunction {
int curYear, curPeriod;
if (reportCode.startsWith("VAT")) {
int[] yearOffSet = {};
Integer yearOffSet = 0;
curPeriod = FormulaHelper.getPeriod(period, yearOffSet, formulaContext);
curYear = FormulaHelper.getYear(year, formulaContext) + yearOffSet[0];
curYear = FormulaHelper.getYear(year, formulaContext) + yearOffSet;
} else if (reportCode.startsWith("CIT.")) {
curYear = FormulaHelper.getYear(year, formulaContext);
curPeriod = 0;
......
......@@ -49,9 +49,9 @@ public class XXFP extends FunctionBase implements FreeRefFunction {
logger.debug(formulaExpression);
Integer curYear = formulaContext.getYear();
int[] yearOffset = {};
Integer yearOffset = 0;
period = getPeriod(period, yearOffset);
curYear = curYear + yearOffset[0];
curYear = curYear + yearOffset;
BigDecimal taxRateVal = new BigDecimal("-1");
if (!taxRate.endsWith("%")) {
......
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