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; ...@@ -5,6 +5,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import pwc.taxtech.atms.dao.FormulaAdminMapper; import pwc.taxtech.atms.dao.FormulaAdminMapper;
import pwc.taxtech.atms.dao.OrganizationMapper;
import pwc.taxtech.atms.dao.ProjectMapper; import pwc.taxtech.atms.dao.ProjectMapper;
import pwc.taxtech.atms.dao.ProjectServiceTypeMapper; import pwc.taxtech.atms.dao.ProjectServiceTypeMapper;
import pwc.taxtech.atms.dao.dao.ProjectDao; import pwc.taxtech.atms.dao.dao.ProjectDao;
...@@ -44,6 +45,7 @@ public class SpringContextUtil implements ApplicationContextAware { ...@@ -44,6 +45,7 @@ public class SpringContextUtil implements ApplicationContextAware {
public static AssetsListMapper assetsListMapper; public static AssetsListMapper assetsListMapper;
public static ProjectMapper projectMapper; public static ProjectMapper projectMapper;
public static CellDataSourceMapper cellDataSourceMapper; public static CellDataSourceMapper cellDataSourceMapper;
public static OrganizationMapper organizationMapper;
/** /**
* 获取bean * 获取bean
...@@ -84,5 +86,6 @@ public class SpringContextUtil implements ApplicationContextAware { ...@@ -84,5 +86,6 @@ public class SpringContextUtil implements ApplicationContextAware {
assetsListMapper = webApplicationContext.getBean(AssetsListMapper.class); assetsListMapper = webApplicationContext.getBean(AssetsListMapper.class);
projectMapper = webApplicationContext.getBean(ProjectMapper.class); projectMapper = webApplicationContext.getBean(ProjectMapper.class);
cellDataSourceMapper = webApplicationContext.getBean(CellDataSourceMapper.class); cellDataSourceMapper = webApplicationContext.getBean(CellDataSourceMapper.class);
organizationMapper = webApplicationContext.getBean(OrganizationMapper.class);
} }
} }
package pwc.taxtech.atms.constant; package pwc.taxtech.atms.constant;
import java.io.File; import java.io.File;
import java.util.Locale;
import java.util.UUID; import java.util.UUID;
public final class Constant { public final class Constant {
...@@ -42,6 +43,7 @@ public final class Constant { ...@@ -42,6 +43,7 @@ public final class Constant {
public static final String IMAGE_FORMART_ = "png"; public static final String IMAGE_FORMART_ = "png";
public static final String EMPTY = ""; public static final String EMPTY = "";
public static final String DateTimeFormate = "{0}年{1}月";
public static class DataSourceName { public static class DataSourceName {
public static final String KeyValueDataSource = "KeyValueDataSource"; public static final String KeyValueDataSource = "KeyValueDataSource";
...@@ -69,4 +71,10 @@ public final class Constant { ...@@ -69,4 +71,10 @@ public final class Constant {
public static String ScanPass = "扫描认证"; public static String ScanPass = "扫描认证";
public static String NotPass = "未认证"; 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 { ...@@ -26,7 +26,10 @@ public class ReportController {
@RequestMapping(value = "updateConfig/{projectId}/{ifDeleteManualDataSource}/{period}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @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) { 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) @RequestMapping(value = "generateByTotal/{projectId}/{ifDeleteManualDataSource}/{period}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
......
...@@ -113,5 +113,5 @@ public interface InputVATInvoiceMapper extends MyVatMapper { ...@@ -113,5 +113,5 @@ public interface InputVATInvoiceMapper extends MyVatMapper {
List<InputVATInvoice> getInputVATInvoiceCountByConditionWithPaging(@Param("paras") InputInvoicePreviewQueryParam param,@Param("limitFrom") int limitFrom); 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 { ...@@ -183,5 +183,5 @@ public interface OutputVATInvoiceMapper extends MyVatMapper {
" ") " ")
List<OutputVATInvoiceInfoDto> queryOutputDetailWithItem(Integer period); 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 ...@@ -86,6 +86,9 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
formulaContext.setReportTemplateGroupID(templateGroupID); formulaContext.setReportTemplateGroupID(templateGroupID);
formulaContext.setProjectID(project.getID()); formulaContext.setProjectID(project.getID());
formulaContext.setYear(project.getYear()); formulaContext.setYear(project.getYear());
formulaContext.setIsYear(period == 0);
formulaContext.setIfRound(true);
formulaContext.setOrganizationID(project.getOrganizationID()); formulaContext.setOrganizationID(project.getOrganizationID());
formulaContext.setIfRound(true); formulaContext.setIfRound(true);
...@@ -135,9 +138,13 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen ...@@ -135,9 +138,13 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
//todo:后面单独处理kv的公式 //todo:后面单独处理kv的公式
if (StringUtils.isNotBlank(v.getFormula()) && !v.getFormula().contains("@")) { if (StringUtils.isNotBlank(v.getFormula()) && !v.getFormula().contains("@")) {
cell.setCellFormula(v.getFormula()); cell.setCellFormula(v.getFormula());
logger.debug("formula:" + v.getFormula());
//kv 公式处理 //kv 公式处理
} else if (v.getFormula().startsWith("@")) { } else if (v.getFormula().startsWith("@")) {
if (StringUtils.isNotBlank(v.getKeyValueParsedFormula())) {
cell.setCellFormula(v.getKeyValueParsedFormula()); cell.setCellFormula(v.getKeyValueParsedFormula());
logger.debug("formula:" + v.getKeyValueParsedFormula());
}
} }
}); });
} }
...@@ -343,7 +350,6 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen ...@@ -343,7 +350,6 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
} }
} }
} }
} else { } else {
return "GenerateReport failed"; return "GenerateReport failed";
} }
...@@ -416,9 +422,10 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen ...@@ -416,9 +422,10 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
* @param workbook 工作簿 * @param workbook 工作簿
*/ */
private void addFunctionsToWorkbook(Workbook workbook, FormulaContext formulaContext) { 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), 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 udfs = new DefaultUDFFinder(functionNames, functionImpls);
UDFFinder udfToolpack = new AggregatingUDFFinder(udfs); UDFFinder udfToolpack = new AggregatingUDFFinder(udfs);
workbook.addToolPack(udfToolpack); workbook.addToolPack(udfToolpack);
......
...@@ -61,9 +61,9 @@ public class FSJZ extends FunctionBase implements FreeRefFunction { ...@@ -61,9 +61,9 @@ public class FSJZ extends FunctionBase implements FreeRefFunction {
year = formulaContext.getYear(); year = formulaContext.getYear();
} }
int[] yearOffset = {}; Integer yearOffset = 0;
period = FormulaHelper.getPeriod(period, yearOffset, formulaContext); period = FormulaHelper.getPeriod(period, yearOffset, formulaContext);
year = year + yearOffset[0]; year = year + yearOffset;
if (accountType == 0) { if (accountType == 0) {
//标准账套 //标准账套
......
...@@ -53,14 +53,14 @@ public class FormulaHelper { ...@@ -53,14 +53,14 @@ public class FormulaHelper {
return columnStr; return columnStr;
} }
public static int getPeriod(int parameterPeriod, int[] yearOffset, FormulaContext formulaFunctionContext) { public static int getPeriod(int parameterPeriod, Integer yearOffset, FormulaContext formulaFunctionContext) {
yearOffset[0] = 0; yearOffset = 0;
if (parameterPeriod == -99) { if (parameterPeriod == -99) {
return parameterPeriod; return parameterPeriod;
} else if (parameterPeriod <= -1) { } else if (parameterPeriod <= -1) {
int period = parameterPeriod + formulaFunctionContext.getPeriod(); int period = parameterPeriod + formulaFunctionContext.getPeriod();
while (period <= 0) { while (period <= 0) {
yearOffset[0]--; yearOffset--;
period += 12; period += 12;
//throw new NotImplementedException(); //throw new NotImplementedException();
} }
......
...@@ -71,17 +71,15 @@ public class FunctionBase { ...@@ -71,17 +71,15 @@ public class FunctionBase {
} }
} }
public int getPeriod(int parameterPeriod, int[] yearOffset) { public int getPeriod(int parameterPeriod, Integer yearOffset) {
if (yearOffset.length == 0) {
yearOffset = new int[10]; yearOffset = 0;
}
yearOffset[0] = 0;
if (parameterPeriod == -99) { if (parameterPeriod == -99) {
return parameterPeriod; return parameterPeriod;
} else if (parameterPeriod <= -1) { } else if (parameterPeriod <= -1) {
int period = parameterPeriod + formulaContext.getPeriod(); int period = parameterPeriod + formulaContext.getPeriod();
while (period <= 0) { while (period <= 0) {
yearOffset[0]--; yearOffset--;
period += 12; period += 12;
} }
return period; return period;
......
...@@ -54,15 +54,15 @@ public class JXFP extends FunctionBase implements FreeRefFunction { ...@@ -54,15 +54,15 @@ public class JXFP extends FunctionBase implements FreeRefFunction {
+ authenticationType + "," + resultType + "," + period + ")"; + authenticationType + "," + resultType + "," + period + ")";
logger.debug(formulaExpression); logger.debug(formulaExpression);
int[] yearOffset = {}; Integer yearOffset = 0;
certificationPeriod = getPeriod(certificationPeriod, yearOffset); certificationPeriod = getPeriod(certificationPeriod, yearOffset);
if (yearOffset[0] < 0) { if (yearOffset < 0) {
return NumberEval.ZERO; return NumberEval.ZERO;
} }
period = getPeriod(period, yearOffset); period = getPeriod(period, yearOffset);
if (yearOffset[0] < 0) { if (yearOffset < 0) {
return NumberEval.ZERO; return NumberEval.ZERO;
} }
......
...@@ -48,9 +48,9 @@ public class JXFPMX extends FunctionBase implements FreeRefFunction { ...@@ -48,9 +48,9 @@ public class JXFPMX extends FunctionBase implements FreeRefFunction {
logger.debug(formulaExpression); logger.debug(formulaExpression);
int curYear = formulaContext.getYear(); int curYear = formulaContext.getYear();
int[] yearOffSet = {}; Integer yearOffSet = 0;
period = getPeriod(period, yearOffSet); period = getPeriod(period, yearOffSet);
curYear = curYear + yearOffSet[0]; curYear = curYear + yearOffSet;
BigDecimal taxRateVal; BigDecimal taxRateVal;
if (taxRate.equals(Constant.Other)) { 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 { ...@@ -62,9 +62,9 @@ public class SGSR implements FreeRefFunction {
int curYear, curPeriod; int curYear, curPeriod;
if (reportCode.startsWith("VAT")) { if (reportCode.startsWith("VAT")) {
int[] yearOffSet = {}; Integer yearOffSet = 0;
curPeriod = FormulaHelper.getPeriod(period, yearOffSet, formulaContext); curPeriod = FormulaHelper.getPeriod(period, yearOffSet, formulaContext);
curYear = FormulaHelper.getYear(year, formulaContext) + yearOffSet[0]; curYear = FormulaHelper.getYear(year, formulaContext) + yearOffSet;
} else if (reportCode.startsWith("CIT.")) { } else if (reportCode.startsWith("CIT.")) {
curYear = FormulaHelper.getYear(year, formulaContext); curYear = FormulaHelper.getYear(year, formulaContext);
curPeriod = 0; curPeriod = 0;
......
...@@ -49,9 +49,9 @@ public class XXFP extends FunctionBase implements FreeRefFunction { ...@@ -49,9 +49,9 @@ public class XXFP extends FunctionBase implements FreeRefFunction {
logger.debug(formulaExpression); logger.debug(formulaExpression);
Integer curYear = formulaContext.getYear(); Integer curYear = formulaContext.getYear();
int[] yearOffset = {}; Integer yearOffset = 0;
period = getPeriod(period, yearOffset); period = getPeriod(period, yearOffset);
curYear = curYear + yearOffset[0]; curYear = curYear + yearOffset;
BigDecimal taxRateVal = new BigDecimal("-1"); BigDecimal taxRateVal = new BigDecimal("-1");
if (!taxRate.endsWith("%")) { 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